Chapter 3. The Resource Manager
3.1. The XAResource Interface
javax.transaction.xa.XAResourceinterface is a Java mapping of the
XAinterface, and defines the contract between a Resource Manager and a Transaction Manager in a distributed transaction processing environment. A resource adapter implements the
XAResourceinterface to support association of a top-level transaction to a resource. A relational database is an example of such a resource.
XAResourceinterface can be supported by any transactional resource adapter that is intended to be used in an environment where transactions are controlled by an external transaction manager. An application can access data through multiple database connections. Each database connection is associated with an
XAResourceobject that serves as a proxy object to the underlying resource manager instance. The transaction manager obtains an
XAResourcefor each resource manager participating in a top-level transaction. The
endmethods associates and dissociate the transaction from the resource.
endinvocations. At transaction commit time, these transactional resource managers are instructed by the transaction manager to prepare, commit, or rollback the transaction according to the two-phase commit protocol.
XAResourcediffers from the standard
XAinterface in the following ways:
- The resource manager initialization is done implicitly by the resource adapter when the connection is acquired. There is no
Rmidis not passed as an argument. Each
Rmidis represented by a separate
- Asynchronous operations are not supported because Java supports multi-threaded processing and most databases do not support asynchronous operations.
- Error return values caused by the improper handling of the
XAResourceobject by the transaction manager are mapped to Java exceptions by the
- The DTP concept of Thread of Control maps to all Java threads with access to the
Connectionobjects. For example, two different threads are able to perform the
endoperations on the same
3.1.1. Extended XAResource Control
XAResourceobject is registered with a JTA-compliant transaction service, you have no control over the order in which it will be invoked during the two-phase commit protocol, with respect to other
XAResourceobjects. However, JBoss Transaction Service supports controlling the order with the two interfaces
com.arjuna.ats.jta.resources.EndXAResource. By inheriting your
XAResourceinstance from either of these interfaces, you control whether an instance of your class will be invoked at the beginning or end of the commit protocol.
prepare) to be enlisted with a transaction which manipulates two-phase aware participants. JBossJTA provides LRCO support.
XAResourceimplementation must extend the
com.arjuna.ats.jta.resources.LastResourceCommitOptimisationmarker interface. When enlisting the resource via
Transaction.enlistResource, JBoss Transaction Service allows only a single
LastResourceCommitOptimisationparticipant to be used within each transaction. Your resource is driven last in the commit protocol, and the
preparemethod is not invoked.
LastResourceCommitOptimisationclass will fail and
falseis returned from
Transaction.enlistResource. You can override this behavior by setting the com.arjuna.ats.jta.allowMultipleLastResources property to
true. Be sure to read the section on enlisting multiple one-phase aware resources fore more information.
3.1.2. Enlisting Multiple One-Phase Aware Resources
preparestate. They commit or rollback immediately when instructed by the transaction coordinator, without knowledge of other resource states and without any way of undoing their actions if subsequent resources make a different choice. This can cause data corruption or heuristic outcomes.
- Wrap the resources in compensating transactions.
- Migrate the legacy implementations to two-phase aware equivalents.
"You have chosen to enable multiple last resources in the transaction manager. This is transactionally unsafe and should not be relied upon.”or, when multiple one-phase resources are enlisted within the transaction,
“This is transactionally unsafe and should not be relied on.”.