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