Suspend TimerTask until the next execution

Posted by user1052518 on Stack Overflow See other posts from Stack Overflow or by user1052518
Published on 2011-11-17T19:33:27Z Indexed on 2011/11/18 1:50 UTC
Read the original article Hit count: 154

Filed under:
|

I am using a TimerTask to run some periodic tasks, the task being processing a set of files. I have a requirement where if the number of files to be processed exceeds a pre-determined limit, the thread suspends execution and waits till the next cycle to start processing the files again. Is there a way to suspend the TimerTask until the next execution period or do I have to extend the TimerTask class to achieve this functionality? I saw there is a TimerTask.cancel method, but this will cancel all further executions of this thread. I don't want this to happen. I just want the thread to be suspended until the next execution period. I don't have the luxury of moving to any of the other concurrent classes in Java as our framework uses TimerTask, and I have to stick with it.

Any suggestions, pointers or tips are greatly appreciated.

thanks,

Asha

© Stack Overflow or respective owner

Related posts about java

Related posts about timertask