Timer
public
class
Timer
extends Object
| java.lang.Object | |
| ↳ | java.util.Timer |
A facility for threads to schedule tasks for future execution in a background thread. Tasks may be scheduled for one-time execution, or for repeated execution at regular intervals.
Corresponding to each Timer object is a single background
thread that is used to execute all of the timer's tasks, sequentially.
Timer tasks should complete quickly. If a timer task takes excessive time
to complete, it "hogs" the timer's task execution thread. This can, in
turn, delay the execution of subsequent tasks, which may "bunch up" and
execute in rapid succession when (and if) the offending task finally
completes.
After the last live reference to a Timer object goes away
and all outstanding tasks have completed execution, the timer's task
execution thread terminates gracefully (and becomes subject to garbage
collection). However, this can take arbitrarily long to occur. By
default, the task execution thread does not run as a daemon thread,
so it is capable of keeping an application from terminating. If a caller
wants to terminate a timer's task execution thread rapidly, the caller