siva636
siva636

Reputation: 16441

@Schedule annotation in Java EE

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.

Upvotes: 3

Views: 6510

Answers (3)

D00de
D00de

Reputation: 918

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.

Upvotes: 0

alexblum
alexblum

Reputation: 2238

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

Upvotes: 1

Majed
Majed

Reputation: 917

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

Upvotes: 1

Related Questions