Describe 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].
Two types of objects are involved in a transaction.
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.
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