Spring Distributed Transactions


An understanding of distributed transactions is not required to understand spring transactions, however, we present it here since it would be good to get the complete picture. Many times a transaction spans multiple systems (on separate hosts). For example, a single transaction may involve a messaging system and a database. Distributed transactions must satisfy all the properties of ACID.


XA stands for extended architecture. It is an X/Open group standard for distributed transactions. Is specifies the interfaces between a transaction manager and one or more resource managers. An example of a resource manager is a JDBC driver. The transaction manager coordinates the transaction between the various resource managers.

Two Phase Commit

A transaction manager coordinates the transaction between various systems involved in the transaction using the two phase commit approach. on a very broad level it consists of two steps. In the first step it polls all resource managers to check whether they are ready for committing the transaction. The resource manager may either reply with ready, not ready or read only. In the second phase the transaction manager tells all the resource managers to perform the actual commit or rollback.

Java Transaction API (JTA)

JTA transaction API specifies interfaces for distributed transactions. These interfaces specify the contract between the transaction manager and the resource manager, application or application server
Important interfaces in JTA

  • javax.transaction.Transaction – contains the following methods : commit,enlistResource,delistResource,getStatus,rollback,setRollbackOnly. This interfaces allows standard transaction operations on the object implementing it
  • javax.transaction.TransactionManager – Contains method that allows the application server to manage transactions. Contains the following methods : begin,commit,getStatus,getTransaction,resume,rollback,setRollbackOnly,setTransactionTimeout,suspend. Note that the transaction is associated with the current thread
  • javax.transaction.UserTransaction – Contains methods that allow an application to manage transaction boundaries. Contains the following methods: begin,commit,getStatus,rollback,setRollbackOnly,setTransactionTimeout
  • javax.transaction.Status – Contains constants for the status of the transaction
  • javax.transaction.xa.XAResource – This interface is the java implementation for the XA protocol. It defines the contract between the transaction manager and the resource manager.

These are the main classes of the Java Transaction API. For the complete list look at the JTA API.

Leave a Reply

Your email address will not be published. Required fields are marked *