Reputation: 932
I have a cosmetic issue while configuring the schedule annotation on one of the methods in my stateless session bean.
@Schedule(minute = "*/5", hour = "*", persistent = false)
@Override
public void retrieveDoc() {
try {
//--- --- --- --- --- --- ---
} catch (InterruptedException ex) {
}
}
I want my method to execute for every 5 minutes. However this execution stops after around 7 days. Is there something that I am missing? I want this method to run after every 5 minutes as long as the server is up and running.
Any hint on this is highly appreciated.
Thanks.
Upvotes: 0
Views: 418
Reputation: 3533
Because this is ejb, it is by default transactional. In order to effectively catch the exception thrown, wrap the logic into a different ejb call specifically calling that method in a diffrent transaction.
@Stateless
public class MySchedules{
@EJB
private MyScheduleService scheduleService;
@Schedule(minute="*/5", hour="*")
public void scheduleMe() {
try {
//The logic here is that you cannot catch an exception
//thrown by the current transaction, but you sure can catch
//an exception thrown by the next transaction started
//by the following call.
scheduleService.doTransactionalSchedule();
}catch(Exception ex) {//log me}
}
}
@Stateless
@TransactionAttribute(REQUIRES_NEW)
public class MyScheduleService {
public void doTransactionalSchedule() {
//do something meaningful that can throw an exception.
}
}
Upvotes: 1
Reputation: 2084
Your timer should go off every five minutes forever. Is it possible you caught an exception in that method? If an exception is thrown inside a @Schedule method, that method will be called again after 5 seconds, and if that fails, the timer dies.
Upvotes: 1