避免在glassfish上清除计时器 [英] Avoid expunging timer on glassfish
问题描述
$ b
@Schedule(second) 使用@Schedule注释的方法有时会被容器调用。 =* / 5,minute =*,hour =*,persistent = false)
public void myTimerMethod()抛出异常{
...
}
问题是在某些情况下,我希望此方法抛出异常以导致正在进行的事务回滚。但如果我这样做超过两次,计时器将被清除而不再被调用!
INFO:EJB5119:清除计时器['68 @@ 1359143163781 @@ server @@ domain1''TimedObject = MyBean''应用程序= My-War''BEING_DELIVERED''PERIODIC''货柜ID = 89072805830524936''Fri Jan 25 21:49:30 CET 2013''0''* / 5#*#*#*#*#*#*#* null #2]失败后的交货
我知道我在#[null]#null#null#true#myTimerMethod#0'可以使用
< domains>来配置在domain.xml中的计时器重新计划。
...
< configs>
< config>
...
< ejb-container session-store =$ {com.sun.aas.instanceRoot} / session-store>
< ejb-timer-service>
< property name =reschedule-failed-timervalue =true>< / property>
< / ejb-timer-service>
< / ejb-container>
...
< / config>
< / configs>
...
< / domains>
但我的问题是,我可以在配置我的应用程序时配置此设置吗?
找不到:
glassfish-resources。 xml
glassfish-ejb-jar.xml
glassfish-web.xml
有没有办法以编程方式做到这一点?可能吗?
(我的理念背后的配置文件,而不是配置服务器这样的服务器配置是这样的,所以我的应用程序应该是可能直接安装在玻璃鱼的全新安装上)
我会用不同的方法。
$ b
不是直接从调度方法抛出异常,而是尝试引入间接级别,如下所示:
...
@Inject RealWorkHere realImplementation;
@Schedule(second =* / 5,minute =*,hour =*,persistent = false)
public void myTimerMethod(){
try {
realImplementation.myTimerMethodImpl()
} catch(Exception x){
//希望记录在某处
}
}
...
其中 RealWorkHere
是具有实际实现的bean in:
@Stateless
公共类RealWorkHere {
@TransactionAttribute(REQUIRES_NEW)
public void myTimerMethod()抛出异常{
}
}
这带来了以下好处: I have a method annotated with @Schedule that is called by the container once in a while. Problem is on certain conditions i want to this method to throw an exception to cause the ongoing transaction to rollback. But if I do this more than two times the timer will be expunged and not called any more! I know i can configure timer rescheduling in domain.xml using But my question is, can I have this setting configured when i deploy my application? Can't find it in: Is there some way to do it programmatically maybe? (My rationale behind behind putting server-configuration like this in config files rather than configuring the server is so my app should be possible to install directly on a fresh installation of glassfish) I'd use a different approach. Instead of throwing an exception directly from the scheduled method, try to introduce a level of indirection as in: where This comes with the benefit of: 这篇关于避免在glassfish上清除计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
参见
@Schedule(second = "*/5", minute = "*", hour = "*", persistent = false)
public void myTimerMethod() throws Exception {
...
}
INFO: EJB5119:Expunging timer ['68@@1359143163781@@server@@domain1' 'TimedObject = MyBean' 'Application = My-War' 'BEING_DELIVERED' 'PERIODIC' 'Container ID = 89072805830524936' 'Fri Jan 25 21:49:30 CET 2013' '0' '*/5 # * # * # * # * # * # * # null # null # null # true # myTimerMethod # 0' ] after [2] failed deliveries
<domains>
...
<configs>
<config>
...
<ejb-container session-store="${com.sun.aas.instanceRoot}/session-store">
<ejb-timer-service>
<property name="reschedule-failed-timer" value="true"></property>
</ejb-timer-service>
</ejb-container>
...
</config>
</configs>
...
</domains>
glassfish-resources.xml
glassfish-ejb-jar.xml
glassfish-web.xml
...
@Inject RealWorkHere realImplementation;
@Schedule(second = "*/5", minute = "*", hour = "*", persistent = false)
public void myTimerMethod(){
try{
realImplementation.myTimerMethodImpl()
}catch (Exception x){
// hopefully log it somewhere
}
}
...
RealWorkHere
is the bean with the actual implementation as in:@Stateless
public class RealWorkHere{
@TransactionAttribute(REQUIRES_NEW)
public void myTimerMethod() throws Exception {
}
}
See also