避免在glassfish上清除计时器 [英] Avoid expunging timer on glassfish

查看:141
本文介绍了避免在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()抛出异常{

}
}

这带来了以下好处:


  • 不在容器初始化的事务中抛出异常(从而避免了清除) b $ b
  • 更好地记录异常情况

  • 清除真实业务交易的分界线


    参见




    I have a method annotated with @Schedule that is called by the container once in a while.

    @Schedule(second = "*/5", minute = "*", hour = "*", persistent = false)
    public void myTimerMethod() throws Exception {
        ...
    }
    

    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!

    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
    

    I know i can configure timer rescheduling in domain.xml using

    <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>
    

    But my question is, can I have this setting configured when i deploy my application?

    Can't find it in:

    glassfish-resources.xml
    glassfish-ejb-jar.xml
    glassfish-web.xml
    

    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:

    ...
    @Inject RealWorkHere realImplementation;
    
    @Schedule(second = "*/5", minute = "*", hour = "*", persistent = false)
    public void myTimerMethod(){
      try{
         realImplementation.myTimerMethodImpl()
      }catch (Exception x){
       // hopefully log it somewhere
      }
    }
    ...
    

    where RealWorkHere is the bean with the actual implementation as in:

    @Stateless
    public class RealWorkHere{
       @TransactionAttribute(REQUIRES_NEW)
       public void myTimerMethod() throws Exception {
    
       }
    }
    

    This comes with the benefit of:

    • Not throwing an exception in a container-initated transaction (thus avoiding the expunging)
    • Better logging of the Exception
    • Clear demarcation of the 'real' business transaction

    See also

    这篇关于避免在glassfish上清除计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆