如何更改 Glassfish 4.1.1 中的 EJB 事务超时?
How to change EJB transaction timeout in Glassfish 4.1.1?
在 Glassfish 中,EJB 事务超时默认设置为 120 秒,我想更改此值。
我知道可以通过在 glassfish-ejb-jar.xml 中定义 "cmt-timeout-in-seconds" 参数来更改它,但我使用带有 EJB 类 的 Web 模块,并使用 glassfish-web.xml分别。
有什么办法可以改变超时时间吗?
更新:
事务服务设置中的事务超时值无效。
@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() 方法。
事务超时的默认值为 0(无超时),而不是 120。 2.1.1版本有Oracle tutorial,看起来还不错。
转到Administrator console (default port is 4848, http://localhost:4848)
左侧菜单:配置 -> server-config -> 交易服务
字段:事务超时
服务器重启
在 GlassFish 4.1 上测试过,在 4.1.1 中应该没有太大区别。
这是一个已报告的错误。
http://java.net/jira/browse/GLASSFISH-21495
我是当我有一个导入大量数据并调用flush的方法时。
即使是web模块,也要添加sun-ejb-jar.xml(或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>
在 Glassfish 中,EJB 事务超时默认设置为 120 秒,我想更改此值。
我知道可以通过在 glassfish-ejb-jar.xml 中定义 "cmt-timeout-in-seconds" 参数来更改它,但我使用带有 EJB 类 的 Web 模块,并使用 glassfish-web.xml分别。
有什么办法可以改变超时时间吗?
更新:
事务服务设置中的事务超时值无效。
@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() 方法。
事务超时的默认值为 0(无超时),而不是 120。 2.1.1版本有Oracle tutorial,看起来还不错。
转到Administrator console (default port is 4848, http://localhost:4848)
左侧菜单:配置 -> server-config -> 交易服务
字段:事务超时
服务器重启
在 GlassFish 4.1 上测试过,在 4.1.1 中应该没有太大区别。
这是一个已报告的错误。
http://java.net/jira/browse/GLASSFISH-21495
我是当我有一个导入大量数据并调用flush的方法时。
即使是web模块,也要添加sun-ejb-jar.xml(或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>