Accessing transactional resources The JTA, or Java Transaction API, is a Java Enterprise API for managing distributed transactions. Distributed transactions are one of the things that make distributed systems more complicated than nondistributed programs.
To understand distributed transactions,you must first understand simple, nondistributed transactions.
A transaction is a group of several operations that must behave atomically, as if they
constitute a single, indivisible operation. Consider a banking application that allows a user
to transfer money from a checking account to a savings account. If the two account balances
are stored in a database, the application must perform two database updates to handle a
transfer—it must subtract money from the checking account and add money to the savings
account. These two operations must behave atomically. To see why, imagine what would
happen if the database server crashed after money had been subtracted from the checking
account but before it had been added to the savings account. The customer would lose
The JTA defines a Java binding for the standard XA API for distributed transactions (XA
is a standard defined by the Open Group). Using the JTA, we can write a program that
communicates with a distributed transaction service and uses that service to coordinate a
distributed transaction that involves, for example, a transfer of money between database
records in two different databases.
Chapter 16 provides a brief general tutorial on the JTA. Since EJBs and EJB containers
provide direct support for distributed transactions using JTA, there is also brief coverage
of the API (as it relates to EJB) in Chapter 6. JDBC drivers can also optionally support
Java Enterprise in a Nutshell, 3rd Edition Page 18 Return to Table of Contents
JTA-enabled distributed transactions, so JTA (as it relates to JDBC) is also briefly
mentioned in Chapter 8.