How to create a timer task which can be cancelled and rescheduled
I have an application which needs to be run every nth minute of an hour n can be 5 , 15 , 30 etc... So I wrote a timer which will be called every 1 minute and I will do current time in minutes % n to check if its time to schedule.
Now problem is that once the task is scheduled at nth minute , I want the timer to pause as it will take more than one minute to complete.
I want to know , is there a way to cancel the timer when job is scheduled and reschedule when the job is done.
I tried using timer.cancel but it throws IllegalState exception.
链接地址: http://www.djcxy.com/p/74912.html上一篇: GC正在使用Java长时间运行计时器
下一篇: 如何创建可以取消和重新计划的计时器任务