如何在Glassfish 4.1.1中更改EJB事务超时



在Glassfish中,EJB事务超时默认设置为120秒,我想更改这个值。

我知道可以通过在glassfish-ejb-jar.xml中定义"cmt timeout in seconds"参数来更改它,但我使用的是包含ejb类的Web模块,并分别使用glassfish-Web.xml。

有什么办法可以更改超时时间吗?

UPD:

"事务服务"设置中的"事务超时"值无效。

@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");
}

上面的代码运行良好。但是如果要将睡眠时间更改为121秒

Thread.sleep(1000 * 121);

在GF服务器日志中,我看到一个错误:

Warning:   EJB5123:Rolling back timed out transaction

之后,服务再次调用doSomething()方法,2分钟后我再次看到错误:

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

并且该服务不再调用doSomething()方法。

即使是web模块,也要添加sun-ejb-jar.xml(或glassfish-ejb-jard.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>

事务超时的默认值是0(无超时),而不是120。有一个2.1.1版的Oracle教程,看起来并没有过时。

  • 转到管理员控制台(默认端口为4848,http://localhost:4848)

  • 左菜单:配置->服务器配置->事务服务

  • 字段:事务超时

  • 服务器重新启动

在GlassFish 4.1上测试,4.1.1中应该没有太大差异。

这是一个已报告的错误。

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

对我来说,就是当我有一个方法导入大量数据并调用flush时。

最新更新