Distributed Transactions   «Prev  Next»

Lesson 5Java JTA: The underlying mechanism
ObjectiveDescribe the underlying Java Transaction Mechanism

JTS and JTA

EJB platforms use the Java Transaction Service (JTS) to propagate transactions.
JTS is a protocol that is implemented by Java-based transaction aware software.
Java Transaction API (JTA) is the interface to the underlying JTS. This interface is accessible from the EJB, the container, the server, and others. The MouseOver below best illustrates the relationship between these. The new entities introduced in the illustration are the Transaction Manager and theApplication Server [1].

Java Transaction API (JTA)
  1. The Transaction Manager (TM) coordinates all activities on behalf of all interested parties. The transaction manager cooperates with all the other transaction managers that are within the scope of the transaction
  2. The application, such as an EJB client or an EJB itself, controls a transaction it starts. The interface between the client and the transaction manager is the javax.transaction.UserTransaction object.
  3. Any resources that wish to take part in a transaction must have a specific resource manager. The resource manager registers itself with the transaction manager and then performs the commit or the rollback when requested by the transaction manager. The resource manager also understands two-phase commits. The resource manager is typically the driver to a persistent data store of some kind.
  4. The Application Server creates and controls transactions in a similar way to the client. An EJB container represents the application server in the EJB universe.
  5. The low-level transaction service provides distributed transaction capabilities and takes care of the propagating transactions from upstream or to downstream objects and resources. It is bundled into the EJB server.

JTA/JTS Service

Recoverable and transactional objects

Two types of objects are involved in a transaction.
  1. A recoverable object is one that manages its state within the context of a transaction. That state can be rolled back or committed on the request of the transaction manager.. An example is a database.
  2. A transactional object is an object that is executing within the context of a transaction but does not have any state that can be recovered, as a recoverable object can. The transactional object can affect the outcome of the transaction by requesting a roll back.
The transaction manager will also notify it when it makes transactional decisions such as rollback and commit.
The transactional object may hold data that it wants to store as part of the transaction. As it is not a recoverable object it does not have the built in mechanisms to store and rollback and recover the data. However the transaction manager will inform it just before the transaction is committed. This allows the bean instance to update its data. The transaction manager will also inform it if a roll back occurred so that the instance can change back its data to its previous state assuming the pervious state was saved and not discarded..

Recoverable objects register themselves

When a recoverable object is asked to change its state, it registers itself with the transaction manager. At that point it makes a temporary change to the state of the persistent data as requested. When the client asks the transaction manager to commit or rollback its state, the transaction manager coordinates the two-phase commit for all the registered recoverable objects.

Java JTA Quiz

Click the Quiz link to test your understanding of transactions.
Java JTA - Quiz
In the next lesson the management of transactions will be discussed.

[1]Application Server: Container to run server side Java