|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
A facility for servlet applications 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.
The ServletTimer
and the related
ServletTimerTask
interfaces are modelled over
java.util.Timer
and java.util.TimerTask
respectively.
Unlike their java.util
counterparts, the servlet timer
facility is defined using interfaces rather than classes. Implementations
may or may not be based on java.util
code.
SIP servlet containers are required to make a ServletTimer
object available to servlet applications as a servlet context attribute
with name "javax.servlet.sip.ServletTimer".
ServletTimerTask
Method Summary | |
void |
schedule(ServletTimerTask task,
long delay)
Schedules the specified task for execution after the specified delay. |
void |
schedule(ServletTimerTask task,
long delay,
long period)
Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay. |
void |
scheduleAtFixedRate(ServletTimerTask task,
long delay,
long period)
Schedules the specified task for repeated fixed-rate execution, beginning after the specified delay. |
Method Detail |
public void schedule(ServletTimerTask task, long delay)
task
- task to be scheduleddelay
- delay in milliseconds before task is to be executedjava.lang.IllegalArgumentException
- if delay
is negative,
or delay + System.currentTimeMillis()
is negativejava.lang.IllegalStateException
- if task was already scheduled
or cancelled, timer was cancelled, or timer thread terminated.public void schedule(ServletTimerTask task, long delay, long period)
In fixed-delay execution, each execution is scheduled relative
to the actual execution time of the previous execution. If an
execution is delayed for any reason (such as garbage collection
or other background activity), subsequent executions will be
delayed as well. In the long run, the frequency of execution will
generally be slightly lower than the reciprocal of the specified
period (assuming the system clock underlying
Object.wait(long)
is accurate).
Fixed-delay execution is appropriate for recurring activities that require "smoothness." In other words, it is appropriate for activities where it is more important to keep the frequency accurate in the short run than in the long run. This includes most animation tasks, such as blinking a cursor at regular intervals. It also includes tasks wherein regular activity is performed in response to human input, such as automatically repeating a character as long as a key is held down.
task
- task to be scheduleddelay
- delay in milliseconds before task is to be executedperiod
- time in milliseconds between successive task executionsjava.lang.IllegalArgumentException
- if delay
is negative,
or delay + System.currentTimeMillis()
is negativejava.lang.IllegalStateException
- if task was already scheduled
or cancelled, timer was cancelled, or timer thread terminated.public void scheduleAtFixedRate(ServletTimerTask task, long delay, long period)
In fixed-rate execution, each execution is scheduled relative to
the scheduled execution time of the initial execution. If an
execution is delayed for any reason (such as garbage collection or
other background activity), two or more executions will occur in
rapid succession to "catch up." In the long run, the frequency of
execution will be exactly the reciprocal of the specified period
(assuming the system clock underlying Object.wait(long)
is accurate).
Fixed-rate execution is appropriate for recurring activities that are sensitive to absolute time, such as ringing a chime every hour on the hour, or running scheduled maintenance every day at a particular time. It is also appropriate for recurring activities where the total time to perform a fixed number of executions is important, such as a countdown timer that ticks once every second for ten seconds. Finally, fixed-rate execution is appropriate for scheduling multiple repeating timer tasks that must remain synchronized with respect to one another.
task
- task to be scheduleddelay
- delay in milliseconds before task is to be executedperiod
- time in milliseconds between successive task executionsjava.lang.IllegalArgumentException
- if delay
is negative,
or delay + System.currentTimeMillis()
is negativejava.lang.IllegalStateException
- if task was already scheduled
or cancelled, timer was cancelled, or timer thread terminated.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |