I have some tasks that are executed with the help of Java Quartz Jobs, but I need to stop some tasks by some condition in my code. I read that this can be done via Interrupt
The best solution in my opinion is the one described in this thread: http://forums.terracotta.org/forums/posts/list/7700.page
I've just introduced a "sleep" after set stop flag to true to allow the job to finish cleanly.
@Override
public void interrupt() throws UnableToInterruptJobException {
stopFlag.set(true);
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
//logger.error("interrupt()", e);
}
Thread thread = runningThread.getAndSet(null);
if (thread != null)
thread.interrupt();
}