|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.webmacro.util.TimeLoop
TimeLoop is a scheduler which can schedule Runnable objects for execution or repeate execution. A TimeLoop is configured with two key parameters: periods and duration.
You can schedule a job to execute once, P periods from now, where P must be less than the number of periods in the TimeLoop.
You can also schedule a job to execute once every P periods, where P must be less than the number of periods in the timeloop. TimeLoop will be somewhat inaccurate in this case unless the number of periods in the TimeLoop is a multiple of P: otherwise it cannot distribute the repeat job evenly over its time periods.
TimeLoop is running a background thread to schedule its jobs. Instances
of this thread are shared by different timeloop objects, that have
the same duration
and periods
settings. If
you do not use the timeloop any longer, you should call its
destroy
method. This will count references to the
background thread transparently and will terminate this thread, if
it is not used any more.
Constructor Summary | |
TimeLoop(long duration,
int periods)
Create an instance of a TimeLoop scheduler. |
Method Summary | |
void |
destroy()
Destroy this scheduler. |
void |
finalize()
Calls destroy to terminate the background thread
if no longer needed. |
void |
schedule(java.lang.Runnable task,
int waitPeriods)
Schedule a job to run in the specified number of waitPeriods. |
void |
scheduleRepeat(java.lang.Runnable task,
int waitPeriods)
Schedule a task to run repeatedly, once every waitPeriods. |
void |
scheduleRepeatTime(java.lang.Runnable task,
long milliseconds)
A convenience method which translates your milliseconds into wait periods. |
void |
scheduleTime(java.lang.Runnable task,
long milliseconds)
A convenience method which translates your milliseconds into wait periods. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public TimeLoop(long duration, int periods)
destroy
method when you no longer need this scheduler.
duration
- duration of each period (in ms)periods
- number of periods for the scheduler.Method Detail |
public void destroy()
public void finalize()
destroy
to terminate the background thread
if no longer needed. You should not rely on this method, but
call destroy
yourself when you no longer need
this scheduler.
public void scheduleRepeat(java.lang.Runnable task, int waitPeriods)
public void scheduleRepeatTime(java.lang.Runnable task, long milliseconds)
public void scheduleTime(java.lang.Runnable task, long milliseconds)
public void schedule(java.lang.Runnable task, int waitPeriods)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |