Java Reference
In-Depth Information
You can cancel either a single task or an entire timer by invoking the
cancel
method of
TimerTask
or
Timer
. Cancelling a task means that it will
not be scheduled in the future. Cancelling a
Timer
object prevents any
future execution of any of its tasks. If you
purge
a timer then all refer-
ences to cancelled tasks are removed from its internal queue of tasks to
schedule.
Each
Timer
object uses a single thread to schedule its task executions.
You can control whether this thread is a daemon thread by the boolean
you specify to the
Timer
constructor.
public
Timer(boolean isDaemon)
Creates a new
Timer
whose underlying thread has its daemon
state set according to
isDaemon
.
public
Timer()
Equivalent to
Timer(false)
.
public
Timer(String name)
Equivalent to
Timer(false)
but gives the associated thread the
given name. This is useful for debugging and monitoring pur-
poses.
public
Timer(String name, boolean isdaemon)
Equivalent to
Timer(isDaemon)
but gives the associated thread
the given name. This is useful for debugging and monitoring
purposes.
If the thread is not specified to be a daemon, it will be a user thread.
When the timer is garbage collectedwhich can only happen when all ref-
erences to it are dropped and no tasks remain to be executedthe user
thread will terminate. You should not rely on this behavior since it de-