1 package compbio.stat.servlet.util;
3 import java.util.TimerTask;
7 * A task that can be scheduled for recurring execution by a {@link Scheduler}.
9 public abstract class SchedulerTask implements Runnable {
11 final Object lock = new Object();
14 static final int VIRGIN = 0;
15 static final int SCHEDULED = 1;
16 static final int CANCELLED = 2;
21 * Creates a new scheduler task.
24 protected SchedulerTask() {
28 * The action to be performed by this scheduler task.
31 public abstract void run();
34 * Cancels this scheduler task.
36 * This method may be called repeatedly; the second and subsequent calls have no effect.
38 * @return true if this task was already scheduled to run
41 public boolean cancel() {
43 if (timerTask != null) {
46 boolean result = (state == SCHEDULED);
53 * Returns the <i>scheduled</i> execution time of the most recent actual execution of
54 * this task. (If this method is invoked while task execution is in progress,
55 * the return value is the scheduled execution time of the ongoing task execution.)
57 * @return the time at which the most recent execution of this task was scheduled
58 * to occur, in the format returned by <code>Date.getTime()</code>. The return value
59 * is undefined if the task has yet to commence its first execution.
62 public long scheduledExecutionTime() {
64 return timerTask == null ? 0 : timerTask.scheduledExecutionTime();