I suspect an exception could make the TimerTask stop running in which case I most likely need a second timetask to monitor that the first is still running?
Update
Thanks for the answers. I had inherited this code so a bit ignorant...
I just saw that if I throw an uncaught exception in my job the TimerThread ceases to run forever.
Run method of TimerThread
showed that if an exception is thrown, my scheduled thread never runs again.
public void run() {
try {
mainLoop();
} finally {
// Someone killed this Thread, behave as if Timer cancelled
synchronized(queue) {
newTasksMayBeScheduled = false;
queue.clear(); // Eliminate obsolete references
}
}
}
The end of the stacktrace will be:
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
So temp solution is to catch EVERYTHING... longer term solution is to move to better scheduling as BalusC states.