EJB中的@Schedule方法在异常之后不执行 [英] @Schedule methods in EJBs aren't executing after Exceptions

查看:213
本文介绍了EJB中的@Schedule方法在异常之后不执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java EE6 Singleton Session Bean中有一个方法,每隔30秒由@Schedule(...)计时器调用。这样可以像预期一样工作,直到异常被抛出并捕获在方法中(异常被抛出并捕获在try-catch块中)。发生异常之后,定时器将停止调用该方法。



无论是否发生异常,我如何强制定时器再次调用该方法? >

最好的问候,



基督教

解决方案

如文档中所述:




  • 可选的persistent元素采用布尔值,用于指定是否自动计时器应该能够在服务器重新启动或崩溃后生存。默认情况下,所有自动计时器都是持久的。


  • 企业bean通常会在事务中创建计时器。如果此事务被回滚,定时器创建也将回滚。类似地,如果一个bean取消了回滚的事务中的定时器,则定时器取消被回退。在这种情况下,定时器的持续时间将被重置,就像从未发生取消一样。




如果计时器遇到失败例外,则可能的方法是在catch块内手动创建一个新的计时器。


I've got a method in a Java EE6 Singleton Session Bean which is called by a @Schedule(...) timer every 30 seconds. This works as expected until an exception is thrown and catched in the method (exception is throw and catched in a try-catch block). After the exception occurs the timer stops calling the method.

How can i force the timer to recall the method again, regardless if an exception has occured or not?

Best regards,

christian

解决方案

As mentioned in documentation :

  • The optional persistent element takes a Boolean value and is used to specify whether the automatic timer should survive a server restart or crash. By default, all automatic timers are persistent.

  • An enterprise bean usually creates a timer within a transaction. If this transaction is rolled back, the timer creation also is rolled back. Similarly, if a bean cancels a timer within a transaction that gets rolled back, the timer cancellation is rolled back. In this case, the timer’s duration is reset as if the cancellation had never occurred.

If the timer fails after encountering exception, then the possible approach left will be to create a new timer manually within the catch block.

这篇关于EJB中的@Schedule方法在异常之后不执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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