I have scheduled a TimerTask to run at a fixed time with a interval of one day using java.util.Timer.scheduleAtFixedRate(). The TimerTask is having a logic to control the excution for a duration say 6 hours. The timer is suppose to start this task next day same given time. But sometime the task is restarted just as soon as it stops after the duration. I have not seen any pattern of this occurance, it just happens randomly. I have tested this by running this application many times but could not identify any particular pattern.
Its something like this.
class App{
public static void main(final String[] args) {
Timer timer = new Timer();
ProcessManagerTask processManager = new ProcessManagerTask()
timer.scheduleAtFixedRate(processManager, today @ 01 AM, 1440 minutes))
//some logic to keep this running forever
}
}
public class ProcessManagerTask extends TimerTask {
public ProcessManagerTask(){
//end time = today @ 7 AM
}
public void run() {
while(end time is not expired){
//do some stuff
}
}
The ProcessManagerTask sometime restart immediately at 7 (when the task is over).
EDIT: Guys any idea why the problem appearing for Timer. I am still not able to figure out.
EDIT [08 April 2011]: Guys problem with Timer is still not resolved. I would appreciated if some one can help.