java.util
Class Timer
java.lang.Object
|
+--java.util.Timer
public class
Timerextends
Object Timer that can run TimerTasks at a later time.
TimerTasks can be scheduled for one time execution at some time in the
future. They can be scheduled to be rescheduled at a time period after the
task was last executed. Or they can be scheduled to be executed repeatedly
at a fixed rate.
The normal scheduling will result in a more or less even delay in time
between successive executions, but the executions could drift in time if
the task (or other tasks) takes a long time to execute. Fixed delay
scheduling guarantees more or less that the task will be executed at a
specific time, but if there is ever a delay in execution then the period
between successive executions will be shorter. The first method of
repeated scheduling is preferred for repeated tasks in response to user
interaction, the second method of repeated scheduling is preferred for tasks
that act like alarms.
The Timer keeps a binary heap as a task priority queue which means that
scheduling and serving of a task in a queue of n tasks costs O(log n).
Since:Author:- Mark Wielaard (mark@klomp.org)
See Also:
void | cancel()
|
void | finalize()
|
void | schedule(java.util.TimerTask task, java.util.Date date)
|
void | schedule(java.util.TimerTask task, java.util.Date date, long period)
|
void | schedule(java.util.TimerTask task, long delay)
|
void | schedule(java.util.TimerTask task, long delay, long period)
|
void | scheduleAtFixedRate(java.util.TimerTask task, java.util.Date date, long period)
|
void | scheduleAtFixedRate(java.util.TimerTask task, long delay, long period)
|
Timer
public Timer()
Creates a new Timer with a non daemon Thread as Scheduler, with normal
priority and a default name.
Timer
public Timer(boolean daemon)
Creates a new Timer with a daemon Thread as scheduler if daemon is true,
with normal priority and a default name.
Parameters:
cancel
public void cancel()
Cancels the execution of the scheduler. If a task is executing it will
normally finish execution, but no other tasks will be executed and no
more tasks can be scheduled.
finalize
protected void finalize()
Tells the scheduler that the Timer task died
so there will be no more new tasks scheduled.
schedule
public void schedule(java.util.TimerTask task, java.util.Date date)
Schedules the task at the specified data for one time execution.
Parameters:
Throws:
schedule
public void schedule(java.util.TimerTask task, java.util.Date date, long period)
Schedules the task at the specified date and reschedules the task every
period milliseconds after the last execution of the task finishes until
this timer or the task is canceled.
Parameters:
Throws:
schedule
public void schedule(java.util.TimerTask task, long delay)
Schedules the task after the specified delay milliseconds for one time
execution.
Parameters:
Throws:
schedule
public void schedule(java.util.TimerTask task, long delay, long period)
Schedules the task after the delay milliseconds and reschedules the
task every period milliseconds after the last execution of the task
finishes until this timer or the task is canceled.
Parameters:
Throws:
scheduleAtFixedRate
public void scheduleAtFixedRate(java.util.TimerTask task, java.util.Date date, long period)
Schedules the task at the specified date and reschedules the task at a
fixed rate every period milliseconds until this timer or the task is
canceled.
Parameters:
Throws:
scheduleAtFixedRate
public void scheduleAtFixedRate(java.util.TimerTask task, long delay, long period)
Schedules the task after the delay milliseconds and reschedules the task
at a fixed rate every period milliseconds until this timer or the task
is canceled.
Parameters:
Throws:
The normal scheduling will result in a more or less even delay in time between successive executions, but the executions could drift in time if the task (or other tasks) takes a long time to execute. Fixed delay scheduling guarantees more or less that the task will be executed at a specific time, but if there is ever a delay in execution then the period between successive executions will be shorter. The first method of repeated scheduling is preferred for repeated tasks in response to user interaction, the second method of repeated scheduling is preferred for tasks that act like alarms.
The Timer keeps a binary heap as a task priority queue which means that scheduling and serving of a task in a queue of n tasks costs O(log n).