JTA Overview
3
2.2. What is JTA?
JTA is short for Sun Microsystems' Java Transaction API and is Sun's (low-level) API for creating transactions in
Java and making your data access operations part of those transactions.
The JTA defines how your application can request transactional functionality on the Java platform. JTA is not
a product in itself, but rather a set of Java interfaces. A vendor-specific JTA implementation referred to as a
transaction manager or transaction service (such as Transactions™) is needed to actually use the functionality
defined in these interfaces. In other words, you can program JTA transactions in your application, but you need the
implementation classes of a JTA-compliant transaction manager vendor in order to run your application.
JTA is a standard part of the Java Enterprise (J2EE) platform and every Enterprise JavaBeans (EJB) application
server should also include a JTA implementation. The JTA is said to be low-level because EJB programmers
typically don't access the JTA API directly or explicitly. Rather, the EJB application server makes the appropriate
calls behind the scenes.
So given that an EJB server will also give you JTA functionality, why should you consider using Atomikos'
TransactionsEssentials? Here are just a few reasons:
• Not all EJB servers will provide a fully functional JTA (even if they claim so). For instance, most -if not all-
open source EJB servers don't even come close to what a transaction manager needs to do, and fail when they
are needed most: after restart or a server crash.
• EJB servers that do provide a reasonable transaction manager are often very expensive, and an overkill for many
solutions that only need a fraction of the J2EE APIs. Atomikos TransactionsEssentials provides transactions at a
fraction of the cost of a full EJB server.
• Atomikos TransactionsEssentials offers more features than defined in the JTA specification.
• Atomikos TransactionsEssentials has better and more functionality than most competitors offer.
• Atomikos TransactionsEssentials was designed for very high performance (there is no extra overhead for JTA
transactions; local transactions and JTA transactions can be expected to be equally fast).
• With Atomikos TransactionsEssentials you can even bring JTA functionality on the J2SE (Java 2 Standard
Edition) platform.
2.3. Two-Phase Commit
In the previous section we have referred to a JTA implementation as a transaction manager or transaction service. A
transaction is a logical unit of work that either happens completely (in all databases or queues that were accessed by
it) or not at all. The transaction manager is the software module that is responsible for ensuring this property. It does
this by executing a two-phase commit termination protocol that addresses all of the resources that a transaction has
used. This two-phase commit happens behind the scenes of your application: you typically don't notice it.
Let us briefly describe two-phase commit with the previous example still in mind. Two-phase commit works in two
phases: a voting phase and a decision phase.
• In the voting (or prepare) phase, the transaction manager will ask both the JMS message queue and the database
whether they can agree with a successful termination or not. Each may return a negative reply, for instance if
there was a time-out which caused the database's work to be rolled back. If one of them replies positively, then
it should make sure it can always make the work permanent (this implies that it can no longer cancel due to an
internal time-out).
• After the transaction manager has received all of the replies (also called 'votes') it will make a global decision on
the outcome of the transaction. This decision will depend on the collected replies: