How to specify transaction timeout for CMT EJB in JBoss EAP 4.x/5.x
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 4.x
- 5.x
Issue
- How do I set transaction timeout for Container Managed Transaction (CMT) EJB in JBoss EAP 4.x/5.x?
Resolution
For EJB2
You can specify the transaction timeout at method level in META-INF/jboss.xml:
<jboss>
<enterprise-beans>
<session>
<ejb-name>EchoSLSB</ejb-name>
<jndi-name>EchoSLSB</jndi-name>
<local-jndi-name>EchoSLSBLocal</local-jndi-name>
<method-attributes>
<method>
<method-name>echo</method-name>
<transaction-timeout>1000</transaction-timeout>
</method>
</method-attributes>
</session>
</enterprise-beans>
</jboss>
For EJB3
You can specify the timeout via an annotation either at method level or class level. Note that the annotation is located in different packages in EAP 4 and 5.
-
EAP 4.x:
@org.jboss.annotation.ejb.TransactionTimeout(1000)The
@TransactionTimeoutannotation is located in$JBOSS_HOME/server/$PROFILE/deploy/ejb3.deployer/jboss-annotations-ejb3.jarfile. -
EAP 5:
@org.jboss.ejb3.annotation.TransactionTimeout(1000)The
@TransactionTimeoutannotation is located in$JBOSS_HOME/common/lib/jboss-ejb3-ext-api.jarfile.
For MDB
You can specify the timeout via an annotation @ActivationConfigProperty(propertyName="transactionTimeout", propertyValue="xxx").
@MessageDriven(name = "TestMDB", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "testQueue"),
@ActivationConfigProperty(propertyName = "transactionTimeout", propertyValue="3000")
})
Note:
- All transaction timeout values are in seconds.
- The specified transaction timeout for EJB2/EJB3 only works on the method where the transaction is actually started. It means this will only work for
Required(where the method starts the transaction) orRequiresNew.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.