edu.emory.mathcs.util.concurrent
Class AlarmClock

java.lang.Object
  extended byedu.emory.mathcs.util.concurrent.AlarmClock

public class AlarmClock
extends java.lang.Object

This class provide some value-added over java.util.Timer: that is, it enables rescheduling of previously scheduled tasks.

Note: it seems that cancelling the task and scheduling a new one in such case usually leads to better designs, so this (experimental) class may not be that useful after all.

Version:
1.0
Author:
Dawid Kurzyniec

Constructor Summary
AlarmClock(java.util.Timer engine, java.lang.Runnable task)
           
 
Method Summary
 boolean cancel()
          Cancel the scheduled task.
 boolean setAlarmDelay(long delay)
          Reschedule previously scheduled task.
 void setAlarmDelayIfSooner(long delay)
          Reschedule previously scheduled task unless it would postpone it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AlarmClock

public AlarmClock(java.util.Timer engine,
                  java.lang.Runnable task)
Method Detail

setAlarmDelayIfSooner

public void setAlarmDelayIfSooner(long delay)
Reschedule previously scheduled task unless it would postpone it. In other words, if the requested delay is longer than the time remaining until the previously scheduled execution, the request is ignored.

Parameters:
delay - the new delay before the task is to be executed, measured from the moment the method is invoked.
Returns:
true if successful, false otherwise (that is, if task is already running or complete)

setAlarmDelay

public boolean setAlarmDelay(long delay)
Reschedule previously scheduled task.

Parameters:
delay - the new delay before the task is to be executed, measured from the moment the method is invoked.
Returns:
true if successful, false otherwise (that is, if task is already running or complete)

cancel

public boolean cancel()
Cancel the scheduled task.

Returns:
true if successful, false otherwise.
See Also:
TimerTask.cancel()