Product SiteDocumentation Site

2.4. TransactionManager

The TransactionManager interface allows the application server to control transaction boundaries on behalf of the application being managed.
To obtain a TransactionManager , invoke the static method com.arjuna.ats.jta.TransactionManager.transactionManager .
The TransactionManager maintains the transaction context association with threads as part of its internal data structure. A thread’s transaction context may be null or it may refer to a specific global transaction. Multiple threads may be associated with the same global transaction. As noted in Section 2.3, “UserTransaction” , nested transactions are not supported.
Each transaction context is encapsulated by a Transaction object, which can be used to perform operations which are specific to the target transaction, regardless of the calling thread’s transaction context.
Table 2.1.  TransactionManager Methods
begin
Starts a new top-level transaction and associates the transaction context with the calling thread. If the calling thread is already associated with a transaction, exception NotSupportedException is thrown.
getTransaction
Returns the Transaction object representing the transaction context which is currently associated with the calling thread. You can use this object to perform various operations on the target transaction.
commit
Completes the transaction currently associated with the calling thread. After it returns, the calling thread is associated with no transaction. If commit is called when the thread is not associated with any transaction context, an exception is thrown. In some implementations, the commit operation is restricted to the transaction originator only. If the calling thread is not allowed to commit the transaction, an exception is thrown. JBoss Transactions does not currently impose any restriction on the ability of threads to terminate transactions.
rollback
Rolls back the transaction associated with the current thread. After the rollback method completes, the thread is associated with no transaction.

In a multi-threaded environment, multiple threads may be active within the same transaction. If checked transaction semantics have been disabled, or the transaction times out, a transaction may terminated by a thread other than the one that created it. In this case, the creator usually needs to be notified. JBoss Transactions notifies the creator during operations commit or rollback by throwing exception IllegalStateException .