Distributed transactions and the JTA

A local transaction is a transaction that communicates with just one resource, so a transaction monitor doesn't occur. The resource manager works with the local transactions at the connection level. Applications working with a single relational database are good candidates to use the local transactions. Otherwise, distributed applications working with several resource managers as messaging systems or databases need a transaction monitor to manage all the resources and connections, so a global or distributed transaction will be more appropriate.

The number of distribution of clients is not important to determine the need for a distributed transaction. When more different components in an application ask the application server to coordinate a transaction working with the same resource manager, a local transaction will be candidate.

Here, ExampleDS is a local DataSource:

<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
<driver>h2</driver>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>20</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>

There are different protocols and specifications written to support and coordinate the distributed transactions. The most popular specification for distributed transactions is the X/Open XA (Open Group's XA Protocol). Other important specifications are the Open Systems Interconnect (OSI) transaction processing protocol defined by the ISO (International Organization for Standards), and the LU 6.2 SNA (Systems Network Architecture) defined by IBM.

Both the applications and application work with JTA API programmatically or declaratively to manage distributed transactions through service provider interfaces (SPI) API that an application server must support and the API provided by Java EE for the application to join and move in a transaction in the javax.transaction package . Also, the X/Open XA protocol can be used through a special java package javax.transaction.xa. This packages contain the interfaces to work with both distributed X/Open XA and local transactions.

Here is an example of XA DataSource configuration:

<xa-datasource jndi-name="java:/jboss/datasources/readcommitted" pool-name="readcommitted">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
<xa-datasource-property name="URL">jdbc:h2:mem:readcommitted</xa-datasource-property>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
</security>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
</xa-datasource>

Most implementations of JTA such as Narayana use the Java Transaction Service (JTS). JTS usage is an optional service providing Java bindings for the CORBA OTS (Object Transaction Service). This chapter doesn't cover this service, but it is important to know this if you need to work with legacy systems such as CORBA.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.171.20