Java Transaction API

Java Transaction API

The Java Transaction API (JTA) is one of the Java EE APIs allowing distributed transactions to be done across multiple XA resources. JTA is a specification developed under the Java Community Process as JSR 907. JTA provides for:

* demarcation of transaction boundaries
* X/Open XA API allowing resources to participate in transactions.

X/Open XA architecture

In the X/Open XA architecture, a transaction manager or transaction processing monitor (TP monitor), coordinates the transactions across multiple resources such as a database. Each resource has its own manager. The resource manager typically has its own API for manipulating the resource, for example the JDBC API used by relational databases. In addition, the resource manager allows a TP monitor to coordinate a distributed transaction between its own and other resource managers. Finally, there is the application which communicates with the TP monitor to begin, commit or rollback the transactions. The application also communicates with the individual resources using their own API to modify the resource.

JTA implementation of the X/Open XA architecture

The JTA API consists of classes in two Java packages:
*
*

The JTA is modelled on the X/Open XA architecture, but it defines two different APIs for demarcating transaction boundaries. It distinguishes between an application server such as an EJB server and an application component. It provides an interface, Javadoc:EE|package=javax.transaction|javax/transaction|TransactionManager, that is used by the application server itself to begin, commit and rollback the transactions. It provides a different interface, the Javadoc:EE|package=javax.transaction|javax/transaction|UserTransaction, that is used by general client code such as a servlet or an EJB to manage the transactions.

The JTA architecture requires that each resource manager must implement the Javadoc:EE|package=javax.transaction.xa|javax/transaction/xa|XAResource interface in order to be managed by the TP monitor. As stated previously, each resource will have its own specific API, for instance:
* relational databases use JDBC
* messaging services use JMS
* generalized EIS (Enterprise Information System) resources use Java EE connector API.

Java Transaction API

The Java Transaction API consists of three elements: a high-level applicationtransaction demarcation interface, a high-level transaction manager interface intendedfor an application server, and a standard Java mapping of the X/Open XA protocolintended for a transactional resource manager.

UserTransaction interface

The javax.transaction.UserTransaction interface provides the application theability to control transaction boundaries programmatically. This interface may be usedby Java client programs or EJB beans.

The UserTransaction.begin method starts a global transaction and associates thetransaction with the calling thread. The transaction-to-thread association is managedtransparently by the Transaction Manager.

Support for nested transactions is not required. The UserTransaction.begin methodthrows the NotSupportedException when the calling thread is already associatedwith a transaction and the transaction manager implementation does not support nestedtransactions.

Transaction context propagation between application programs is provided by theunderlying transaction manager implementations on the client and server machines.The transaction context format used for propagation is protocol dependent and must benegotiated between the client and server hosts. For example, if the transaction manageris an implementation of the JTS specification, it will use the transaction contextpropagation format as specified in the CORBA OTS 1.1 specification. Transactionpropagation is transparent to application programs.

UserTransaction support in EJB server

EJB servers are required to support the UserTransaction interface for use by EJBbeans with the TX_BEAN_MANAGED transaction attribute. The UserTransactioninterface is exposed to EJB components through the EJBContext interface using thegetUserTransaction method. Thus, an EJB application does not interface with theTransaction Manager directly for transaction demarcation; instead, the EJB bean relieson the EJB Server to provide support for all of its transaction work as defined in theEnterprise JavaBeans Specification [5] . (The underlying interaction between the EJBServer and the TM is transparent to the application.)

The code sample below illustrates the usage of UserTransaction by a TX_BEAN_MANAGED EJB session bean:

// In the session bean’s setSessionContext method,// store the bean context in an instance variable

this.ctx = sessionContext;

// somewhere else in the bean’s business logicUserTransaction utx = ctx.getUserTransaction();

// start a transactionutx.begin();

// Do work

// Commit itutx.commit();

UserTransaction support in JNDI

The UserTransaction should be available under java:comp/UserTransaction (if a JTA implementation is installed in the environment).

UserTransaction support in J2SE

You don't necessarily need an application server to have JTA or UserTransaction functionality. Independent JTA implementations exist (see the links section below) so that you can even also have JTA/XA reliability in regular Java applications. Especially when combined with tools like Spring, this can give an interesting and powerful paradigm for developing reliable Java applications...

See also

* Java transaction service

External links

* [http://java.sun.com/products/jta/ JTA specifications]
* [http://www.jcp.org/en/jsr/detail?id=907 JSR 907]
* [http://www.atomikos.com/products/transactionsJTA/evaluate.html Atomikos open source JTA implementation - for JTA in J2SE]
* [http://www.onjava.com/pub/a/onjava/2006/02/08/j2ee-without-application-server.html An article on J2EE (and JTA) without application server]


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • Java Transaction API — Maintainer Java Community Process Entwickler Sun Microsystems Aktuelle Version 1.1. (1. November 2002) Betriebssystem plattformunabhä …   Deutsch Wikipedia

  • Java Transaction API — Java Transaction API, сокращенно JTA  Java API для транзакций. Определяет взаимодействие между менеджером транзакций и другими участниками распределенной транзакционной системы. JTA  спецификация, разработанная в рамках Java Community… …   Википедия

  • Java Transaction API — JTA (del inglés Java Transaction API API para transacciones en Java) es parte de Java EE APIs, JTA establece una serie de Interfaces java entre el manejador de transacciones y las partes involucradas en el sistema de transacciones distribuidas:… …   Wikipedia Español

  • Java Transaction API — Java Transaction (JTA) est une API présente dans la spécification J2EE. JTA fournit des interfaces Java standards entre un gestionnaire de transaction et les différentes parties impliquées dans un système de transactions distribuées : le… …   Wikipédia en Français

  • Java Transaction Service — (JTS) ist ein Begriff aus der Softwareentwicklung mit Java. Bei der Kommunikation von mehreren Komponenten einer oder mehrerer Anwendungen miteinander kommt es häufig darauf an, diese Kommunikation und die daraus resultierenden Arbeitsschritte in …   Deutsch Wikipedia

  • Java Persistence API — The Java Persistence API, sometimes referred to as JPA, is a Java programming language framework that allows developers to manage relational data in Java Platform, Standard Edition and Java Platform, Enterprise Edition applications.The Java… …   Wikipedia

  • Java 2 Enterprise Edition — Java Platform, Enterprise Edition, abgekürzt Java EE oder früher J2EE, ist die Spezifikation einer Softwarearchitektur für die transaktionsbasierte Ausführung von in Java programmierten Anwendungen und insbesondere Web Anwendungen. Sie ist eine… …   Deutsch Wikipedia

  • Java 2 Platform Enterprise Edition — Java Platform, Enterprise Edition, abgekürzt Java EE oder früher J2EE, ist die Spezifikation einer Softwarearchitektur für die transaktionsbasierte Ausführung von in Java programmierten Anwendungen und insbesondere Web Anwendungen. Sie ist eine… …   Deutsch Wikipedia

  • Java EE — Java Platform, Enterprise Edition, abgekürzt Java EE oder früher J2EE, ist die Spezifikation einer Softwarearchitektur für die transaktionsbasierte Ausführung von in Java programmierten Anwendungen und insbesondere Web Anwendungen. Sie ist eine… …   Deutsch Wikipedia

  • Java Platform Enterprise Edition — Java Platform, Enterprise Edition, abgekürzt Java EE oder früher J2EE, ist die Spezifikation einer Softwarearchitektur für die transaktionsbasierte Ausführung von in Java programmierten Anwendungen und insbesondere Web Anwendungen. Sie ist eine… …   Deutsch Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”