21 - Transaction Timeouts

Transaction Timeouts

Transaction timeout is the maximum time that the transaction is allowed to run within.

For Bean Managed Transactions, you can use the method setTransactionTimeout of the UserTransaction interface to set the timeout, for Container Managed Transactions, server specific configurations should be used (i.e. for JBOSS, you can use the annotation org.jboss.ejb3.annotation.TransactionTimeout).


@TransactionTimeout(unit=TimeUnit.MINUTES, value=10)
public void doAction() {

The doAction method transaction will be valid for maximum 10 minutes, the same can be handled with the following on bean managed transactions:

public void doAction() {
    try {
        ut.setTransactionTimeout(60 * 10);

Note that the method takes the parameters as seconds (i.e. 10 minutes = 10 * 60).

Like us on Facebook