问题描述
我使用以下注释在5分钟内调用无状态会话bean:
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.
推荐答案
要知道对象是否有过期日期,可以使用getTimers()返回该定时器的对象,然后使用此方法 getTimeRemaining()
知道它是否有截止日期。
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.
无论如何,你可以使用这个注释 @Timeout
在发生超时时执行某些操作:
anyway, you can use this annotation @Timeout
to do something in case of timeout happens :
@Timeout
public void timeout(Timer timer) {
System.out.println("do something ... ");
}
您可以在此处打印日期以了解超时发生的时间..
you can print the date here to know when the timeout happens..
您正在使用自动计时器并在 ejb-jar.xml 配置它,所以请尝试查看 ejb- jar.xml ,看看那里是否有过期日期。
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 ..
这篇关于Java EE中的@Schedule注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!