How to change EJB transaction timeout in Glassfish 4.1.1?

大城市里の小女人 提交于 2019-12-10 16:22:42

问题


In Glassfish the EJB transaction timeout is set to 120 seconds by default, and I want to change this value.

I know that it can be changed by defining the "cmt-timeout-in-seconds" param in the glassfish-ejb-jar.xml, but I use the Web module with EJB classes in it, and use the glassfish-web.xml respectively.

Is there any way to change the timeout?

UPD:

The Transaction Timeout value in the Transaction Service settings has no effect.

@Schedule(minute = "*/5", hour = "*", persistent = false)
public void doSomething() {
    log.info("Started");
    try {
        Thread.sleep(1000 * 119);
    } catch (InterruptedException ex) {
        log.info("Interrupted", ex);
    }
    log.info("Finished");
}

The code above works fine. But if to change the sleep time to 121 seconds

Thread.sleep(1000 * 121);

in the GF Server log I see an error:

Warning:   EJB5123:Rolling back timed out transaction

After this, the service invokes the doSomething() method once more, and in 2 minutes I see errors again:

Warning:   EJB5123: Rolling back timed out transaction
Info:   EJB5119:Expunging timer [...] after [2] failed deliveries

and the service doesn't invoke the doSomething() method anymore.


回答1:


Even if it's a web module, add the sun-ejb-jar.xml (or glassfish-ejb-jar.xml):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
<sun-ejb-jar>
    <enterprise-beans>
         <ejb>
            <ejb-name>YourEjbName</ejb-name>
            <cmt-timeout-in-seconds>1200</cmt-timeout-in-seconds>
         </ejb>
    </enterprise-beans>
</sun-ejb-jar>



回答2:


The default value for transaction timeout is 0 (no timeouts), not 120. There is Oracle tutorial for version 2.1.1 which looks like not outdated.

  • Go to Administrator console (default port is 4848, http://localhost:4848)

  • Left menu: Configurations -> server-config -> Transaction Service

  • Field: Transaction Timeout

  • Server restart

Tested on GlassFish 4.1, shouldn't be much of a difference in 4.1.1.




回答3:


This is a reported bug.

http://java.net/jira/browse/GLASSFISH-21495

With me is when I have a method importing a large amount of data and calling flush.



来源:https://stackoverflow.com/questions/34631364/how-to-change-ejb-transaction-timeout-in-glassfish-4-1-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!