@Schedule annotation in Java EE

丶灬走出姿态 提交于 2020-01-04 02:57:29

问题


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.


回答1:


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 :

@Timeout
public void timeout(Timer timer) {
    System.out.println("do something ... ");
}

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




回答2:


In Glassfish under Configuration -> server-config -> EJB-Container -> EJB-Timeservice new property: reschedule-failed-timer = true




回答3:


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.



来源:https://stackoverflow.com/questions/5833900/schedule-annotation-in-java-ee

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!