85 long period = 0; 86 87 /** 88 * Creates a new timer task. 89 */ 90 protected TimerTask() { 91 } 92 93 /** 94 * The action to be performed by this timer task. 95 */ 96 public abstract void run(); 97 98 /** 99 * Cancels this timer task. If the task has been scheduled for one-time 100 * execution and has not yet run, or has not yet been scheduled, it will 101 * never run. If the task has been scheduled for repeated execution, it 102 * will never run again. (If the task is running when this call occurs, 103 * the task will run to completion, but will never run again.) 104 * 105 * <p>Note that calling this method from within the <tt>run</tt> method of 106 * a repeating timer task absolutely guarantees that the timer task will 107 * not run again. 108 * 109 * <p>This method may be called repeatedly; the second and subsequent 110 * calls have no effect. 111 * 112 * @return true if this task is scheduled for one-time execution and has 113 * not yet run, or this task is scheduled for repeated execution. 114 * Returns false if the task was scheduled for one-time execution 115 * and has already run, or if the task was never scheduled, or if 116 * the task was already cancelled. (Loosely speaking, this method 117 * returns <tt>true</tt> if it prevents one or more scheduled 118 * executions from taking place.) 119 */ 120 public boolean cancel() { 121 synchronized(lock) { 122 boolean result = (state == SCHEDULED); 123 state = CANCELLED; 124 return result; 125 } 126 } 127 128 /** 129 * Returns the <i>scheduled</i> execution time of the most recent 130 * <i>actual</i> execution of this task. (If this method is invoked 131 * while task execution is in progress, the return value is the scheduled 132 * execution time of the ongoing task execution.) 133 * 134 * <p>This method is typically invoked from within a task's run method, to 135 * determine whether the current execution of the task is sufficiently 136 * timely to warrant performing the scheduled activity: 137 * <pre>{@code | 85 long period = 0; 86 87 /** 88 * Creates a new timer task. 89 */ 90 protected TimerTask() { 91 } 92 93 /** 94 * The action to be performed by this timer task. 95 */ 96 public abstract void run(); 97 98 /** 99 * Cancels this timer task. If the task has been scheduled for one-time 100 * execution and has not yet run, or has not yet been scheduled, it will 101 * never run. If the task has been scheduled for repeated execution, it 102 * will never run again. (If the task is running when this call occurs, 103 * the task will run to completion, but will never run again.) 104 * 105 * <p>Note that calling this method from within the {@code run} method of 106 * a repeating timer task absolutely guarantees that the timer task will 107 * not run again. 108 * 109 * <p>This method may be called repeatedly; the second and subsequent 110 * calls have no effect. 111 * 112 * @return true if this task is scheduled for one-time execution and has 113 * not yet run, or this task is scheduled for repeated execution. 114 * Returns false if the task was scheduled for one-time execution 115 * and has already run, or if the task was never scheduled, or if 116 * the task was already cancelled. (Loosely speaking, this method 117 * returns {@code true} if it prevents one or more scheduled 118 * executions from taking place.) 119 */ 120 public boolean cancel() { 121 synchronized(lock) { 122 boolean result = (state == SCHEDULED); 123 state = CANCELLED; 124 return result; 125 } 126 } 127 128 /** 129 * Returns the <i>scheduled</i> execution time of the most recent 130 * <i>actual</i> execution of this task. (If this method is invoked 131 * while task execution is in progress, the return value is the scheduled 132 * execution time of the ongoing task execution.) 133 * 134 * <p>This method is typically invoked from within a task's run method, to 135 * determine whether the current execution of the task is sufficiently 136 * timely to warrant performing the scheduled activity: 137 * <pre>{@code |