|
Problem |
Prior to WebSphere® Application Server Version 6 there is
only a global configuration setting for transaction timeout. This technote
describes a method you can use to set a transaction timeout for a single
enterprise bean. |
|
Solution |
For a Bean Managed Persistence (BMP) Enterprise Java™
Bean:
You can set the transaction timeout programmatically for a Bean Managed
Persistence (BMP) EJB as follows:
getEntityContext().getUserTransaction().setTransactionTimeout(int
seconds);
The new timeout value applies to all transactions that subsequently start
on that thread; it does not apply to any transactions that have already
started.
For a Container-Managed Persistence (CMP) enterprise bean or a session
enterprise bean:
You can set the transaction timeout programmatically by accessing the
UserTransaction before the enterprise bean is called. For example, a
servlet method can start a UserTransaction, modify the transaction
timeout, end the transaction, and then call a CMP enterprise bean. The new
transaction timeout is in effect for the CMP method transaction.
You can set the transaction timeout in a session enterprise bean method
that calls another enterprise bean. When the default transaction attribute
value (REQUIRED) is used, the enterprise bean container starts a
transaction when the enterprise bean method is called. You cannot start a
UserTransaction in a method that is already in a global transaction. You
must set the transaction attribute to NOT_SUPPORTED to allow the
UserTransaction in a session enterprise bean. All calls to a enterprise
bean from in this method have the new transaction timeout. |
|
|
|
|
|
|