Java EE 中的 @Schedule 注释
我使用以下注释每 5 分钟调用一次无状态会话 bean:
@Schedule(second = "0", minute = "0/5", hour = "*")
我按预期工作,只是它会在几天后自行停止。我想可能有一个默认的生命周期,但我不知道如何覆盖它。
请帮助我将调度程序配置为无限期运行。
I use the following annotation to call a stateless session bean once a 5 minutes:
@Schedule(second = "0", minute = "0/5", hour = "*")
I works as expected, except it stops itself after a few days. I guess there may be a default lifetime and I do not know how to override it.
Please help me to configure the scheduler to run indefinitely.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要知道您的对象是否有到期日期,您可以使用 getTimers() 返回该计时器的对象,然后使用此方法
getTimeRemaining()
来了解它是否有到期日期。无论如何,您可以使用此注释@Timeout在发生超时的情况下执行某些操作:
您可以在此处打印日期以了解超时何时发生..
您正在使用“自动计时器”的另一件事是配置在 ejb-jar.xml 中,因此请尝试查看 ejb-jar.xml 以查看那里是否有过期日期。
to know if there is expiration date for your object you can use getTimers() to return an object of that timer then use this method
getTimeRemaining()
to know if there is expiration date for it.anyway, you can use this annotation
@Timeout
to do something in case of timeout happens :you can print the date here to know when the timeout happens..
another thing you are using "Automatic Timers" and it's configured at ejb-jar.xml so try to take a look at ejb-jar.xml to see if there is expiration date there ..
在 Glassfish 下的配置 ->服务器配置-> EJB-容器-> EJB-Timeservice 新属性:reschedule-failed-timer = true
In Glassfish under Configuration -> server-config -> EJB-Container -> EJB-Timeservice new property: reschedule-failed-timer = true
您的 @Schedule 注释看起来正确,因此您应该检查的第一件事是日志并查看您的计划方法中是否存在异常。
根据规范,如果在 Timer 方法内引发异常,该方法将被再次调用,如果再次失败,计时器将关闭。
Your @Schedule annotation look correct, so first thing you should check is logs and see if there are exceptions in your scheduled methods.
As per specification if an exception is thrown inside a Timer method, that method will be called once more and if it fails again the timer is shut down.