Bean-Managed EJBs

Frank 30.04.2014

There are situations in which a transaction cannot be completed in the maximum transaction time specified by the Application Server. To increase this time no container-managed beans can be used but rather a bean-managed bean. This is done as follows:

@Stateless
@TransactionManagement(value=TransactionManagementType.BEAN)
public class XXX {
     @Resource
     private UserTransaction userTransaction;

     @Resource
     private SessionContext sessionContext;
     public void method() throws Eception {
          userTransaction.setTransactionTimeout(300);
          userTransaction.begin();
          try{
               ...
               userTransaction.commit();
          } catch(Exception e){
               userTransaction.rollback();
               throw e;
          }
     }
}

But beware: WebSphere Application Server specifies two timeout limits:

Total Transaction Lifetime Timeout:
Specifies the maximum amount of time, in seconds, that the J2EE server waits for an application transaction that originated in this server to complete if the application transaction does not set its own timeout value
through the UserTransaction.setTransactionTimeout() method.
Default: 120 seconds

Maximum transaction timeout:
Specifies the maximum amount of time, in seconds, that the J2EE server waits for an application transaction that is propagated into this server to complete. This value also applies to transactions that are started in this server, if their associated applications do not set a transaction timeout and the total transaction lifetime timeout is set to 0. This value constrains the upper bound of all other timers. If an application uses the UserTransaction.setTransactionTimeout() method to specify a longer length of time, then the J2EE server changes the application setting to the value specified for the Maximum transaction timeout property.
Default: 300 seconds

The maximum transaction timeout cannot be changed by the application. Each transaction is terminated after this time.

Lernen Sie mehr über:

WebSphere Application Server

WebSphere Portal Server

IBM DataPower

IBM BPM | Process Server

IBM LDAP

Interessantes

Über Uns

Unsere Arbeit

Unsere Partner

Unser Blog

IBM Produkte

Software Engineering

IT Architecture

Workshops

Unternehmen

Produkte

Services

Lösungen