CONTENTS | PREV | NEXT | INDEX J2EE BluePrints



8.4 JTA Transactions

A JTA transaction is a transaction managed and coordinated by the J2EE platform. A J2EE product is required to support JTA transactions according to the transaction requirements defined in the J2EE specification. A JTA transaction can span multiple components and enterprise information systems. They are propagated automatically between components and to enterprise information systems accessed by components within that transaction. For example, a JTA transaction may be comprised of a servlet or JSP page accessing multiple enterprise beans, some of which access one or more relational databases.

There are two ways to begin a JTA transaction. A component can begin a JTA transaction using the JTA javax.transaction.UserTransaction interface. For an enterprise bean, a JTA transaction might also be started automatically by the EJB container if the bean uses container-managed transaction demarcation.

The main benefit of using JTA transactions is the ability to combine multiple components and enterprise information system accesses into one single transaction with little programming effort. For example, if a component A begins a JTA transaction and invokes a method of component B, the transaction will be propagated transparently from component A to B by the platform. Similarly, if component A updates a table in a relational database, the update will automatically be under the scope of the same transaction. No extra programming is required to propagate transactions between multiple components and enterprise information systems. In addition, enterprise beans using container-managed transaction demarcation will not need to begin or commit transactions programmatically as the demarcation is handled automatically by the EJB container.

It is recommend that an enterprise information system, such as a database, be accessed within the scope of a JTA transaction. Accessing an enterprise information system within a transaction provides some guarantee on the consistency and integrity of the data. In addition, using a JTA transaction allows work performed by multiple components through multiple enterprise information system connections to be grouped as an atomic unit. It also allows work performed on one or more independent enterprise information systems to be grouped as an atomic unit if the J2EE product supports two-phase commit.


8.4.1 JTA and JTS

JTA allows applications to access transaction management in a manner that is independent of a specific implementation. JTA specifies standard Java interfaces between a transaction manager and the parties involved in a distributed transaction system: the transactional application, the J2EE server, and the manager that controls access to the shared resources affected by the transactions.

JTS specifies the implementation of a transaction manager that supports JTA and implements the Java mapping of the OMG Object Transaction Service (OTS) 1.1 specification at the level below the API. JTS propagates transactions using IIOP. A JTS transaction manager provides the services and management functions required to support transaction demarcation, transactional resource management, synchronization, and transaction context propagation.

An Application Component Provider uses the JTA UserTransaction interface to demarcate JTA transaction boundaries in components. The JTS
TransactionManager and XAResource interfaces are low-level APIs between a J2EE server and enterprise information system resource managers and are not intended to be used by applications.

A J2EE platform might choose to use a JTS implementation to support the transaction semantics defined in J2EE specification. An example is the J2EE SDK. The JTS implementation is transparent to J2EE components. Components should never interact directly with JTS. Instead, they should use the JTA
UserTransaction interface for transaction demarcation.



CONTENTS | PREV | NEXT | INDEX
Copyright © 2001 Sun Microsystems, Inc. All Rights Reserved.