Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to cancel a timer's existing schedule

Currently I am using a timer to execute some function every interval time. However, later on when I want to change the interval of executing the function, I cannot cancel the previous schedule. how this can be solved? Thanks

like image 530
user301 Avatar asked Oct 27 '11 08:10

user301


1 Answers

With the timer.cancel() method you can cancels the Timer and all scheduled tasks. (see API documentation) or you can call the cancel method on your TimerTask timertask.cancel() (see API documentation)

If you want to change the scheduled time you should cancel the TimerTask and add a new TimerTask.

like image 83
Mats Hofman Avatar answered Nov 14 '22 01:11

Mats Hofman