Timers schedule one-shot or recurring tasks
for execution;
When a timer is no longer needed, users should call cancel()
, which releases the timer's thread and other resources. Timers not explicitly cancelled may hold resources indefinitely。
定时器会定期执行我们的task线程:
定时器周期由 task执行时间与定时器设定设定时间中大的决定。
如果task被某个定时占用了,那么这时不能将它指定到其他定时器。
释放定时器资源:
cancel();调用这个函数之后就无法再使用该定时器了。
purge();这个函数释放被cancel了的task,给其他定时器使用。