Benefits
Consider the following illustration of deferred
enlistment:
- An application component that uses deferred enlistment calls the getConnection method
from within a global transaction.
- The application component does not immediately use the connection.
- When the application issues the call for initial use of the connection,
the transaction manager intercepts the call.
- The transaction manager enlists the XA resource for the connection and
calls the XAResource.start method.
- The connection manager associated with the XA resource sends the call
to the database.
Given the same scenario, but the application component
does not use
deferred enlistment, the component container immediately enlists the connection
in the transaction. Thus the application server incurs, for no purpose, an
additional load of all of the overhead associated with that transaction. For
XA connections, this overhead includes the two phase commit (2PC) protocol
to the resource manager.
Deferred enlistment offers better performance in
the case where a connection is obtained, but not used, within the UOW scope.
The technique saves the cost of transaction participation until the UOW in
which participation must occur.
Check with your resource adapter provider
if you need to know if the resource adapter provides this functionality. The
WebSphere Application Server relational resource adapter automatically supports
deferred enlistment.
Incorporating deferred enlistment in your code
The
J2EE Connector Architecture (JCA) Version 1.5 specification calls the deferred
enlistment technique
lazy transaction enlistment optimization. This
support comes through a marker interface (LazyEnlistableManagedConnection)
and a new method on the connection manager (LazyEnlistableConnectionManager()):
package javax.resource.spi;
import javax.resource.ResourceException;
import javax.transaction.xa.Xid;
interface LazyEnlistableConnectionManager { // application server
void lazyEnlist(ManagedConnection) throws ResourceException;
}
interface LazyEnlistableManagedConnection { // resource adapter
}