{@code Timer}s are used to schedule jobs for execution in a background process. A single thread is used for the scheduling and this thread has the option of being a daemon thread. By calling {@code cancel} you can terminate a{@code Timer} and its associated thread. All tasks which are scheduled to run afterthis point are cancelled. Tasks are executed sequentially but are subject to the delays from other tasks run methods. If a specific task takes an excessive amount of time to run it may impact the time at which subsequent tasks may run.
The {@code TimerTask} does not offer any guarantees about the real-time nature ofscheduling tasks as its underlying implementation relies on the {@code Object.wait(long)} method.
Multiple threads can share a single {@code Timer} without the need for their ownsynchronization.
A {@code Timer} can be set to schedule tasks either at a fixed rate orwith a fixed period. Fixed-period execution is the default.
The difference between fixed-rate and fixed-period execution is the following: With fixed-rate execution, the start time of each successive run of the task is scheduled in absolute terms without regard for when the previous task run actually took place. This can result in a series of bunched-up runs (one launched immediately after another) if busy resources or other system delays prevent the {@code Timer} from firing for an extended time.With fixed-period execution, each successive run of the task is scheduled relative to the start time of the previous run of the task, so two runs of the task are never fired closer together in time than the specified {@code period}.
@see TimerTask
@see java.lang.Object#wait(long)