Advertise with us

Our eBooks

How to increase the Transaction Timeout in JBoss / WildFly

Transaction timeout in WildFly / JBoss can be configured in the transactions subsystem or at EJB level. When the transaction is configured in the transactions subsystem it will be the default transaction timeout for all JTA transactions. When configured at EJB level it will be specific of that EJB.

Configuring Transaction timeout in the transactions subsystem

Out of box, the transactions subsystem does not show the default value of the JTA transaction timeout:

<subsystem xmlns="urn:jboss:domain:transactions:5.0">
    <core-environment node-identifier="${jboss.tx.node.id:1}">
        <process-id>
            <uuid/>
        </process-id>
    </core-environment>
    <recovery-environment socket-binding="txn-recovery-environment" status-socket-binding="txn-status-manager"/>
    <coordinator-environment statistics-enabled="${wildfly.transactions.statistics-enabled:${wildfly.statistics-enabled:false}}"/>
    <object-store path="tx-object-store" relative-to="jboss.server.data.dir"/>
</subsystem>

The value of default-timeout can be configured through the coordinator-environment element as follows:

<coordinator-environment default-timeout="300"/>

Here is how tou can increase the default transaction timeout with the CLI:

/subsystem=transactions:write-attribute(name=default-timeout,value=400)
{"outcome" => "success"}

Configuring the Transaction Timeout in EJBs

The transaction timeout can also be configured at deployment level. Here is how to it with the @org.jboss.ejb3.annotation.TransactionTimeout annotation:

import java.util.concurrent.TimeUnit;
import org.jboss.ejb3.annotation.TransactionTimeout;

@Stateless
public class SampleBean 
{

  @TransactionTimeout(value = 30, unit = TimeUnit.SECONDS)
  public String doSomething() throws RuntimeException
  {
    //
  }
}

You can also use the jboss-ejb3.xml descriptor to set the transaction timeout:

<jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
               xmlns="http://java.sun.com/xml/ns/javaee"
               xmlns:tx="urn:trans-timeout"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd
http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd
urn:trans-timeout http://www.jboss.org/j2ee/schema/trans-timeout-1_0.xsd"
               version="3.1"
               impl-version="2.0">
    <enterprise-beans>
        <session>
            <ejb-name>SampleBean</ejb-name>
            <ejb-class>com.acme.SampleBean</ejb-class>
            <session-type>Stateless</session-type>
        </session>
    </enterprise-beans>
    <assembly-descriptor>
        <container-transaction>
            <method>
                <ejb-name>SampleBean</ejb-name>
                <method-name>*</method-name>
                <method-intf>Local</method-intf>
            </method>
            <tx:trans-timeout>
                <tx:timeout>30</tx:timeout>
                <tx:unit>Seconds</tx:unit>
            </tx:trans-timeout>
        </container-transaction>
    </assembly-descriptor>
</jboss:ejb-jar>

On the other hand, if you are using Message Driven Beans, you can set the transactionTimeout as ActivationConfigProperty of your MDB:

@MessageDriven(name = "TestMDB", activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "testQueue"),
        @ActivationConfigProperty(propertyName = "transactionTimeout", propertyValue="4")
        })
© 2021 mastertheboss.com. All Rights Reserved.

Please publish modules in offcanvas position.