1 7 8 package java.util; 9 10 18 19 public abstract class TimerTask implements Runnable { 20 23 final Object lock = new Object (); 24 25 28 int state = VIRGIN; 29 30 33 static final int VIRGIN = 0; 34 35 39 static final int SCHEDULED = 1; 40 41 45 static final int EXECUTED = 2; 46 47 50 static final int CANCELLED = 3; 51 52 57 long nextExecutionTime; 58 59 64 long period = 0; 65 66 69 protected TimerTask() { 70 } 71 72 75 public abstract void run(); 76 77 99 public boolean cancel() { 100 synchronized(lock) { 101 boolean result = (state == SCHEDULED); 102 state = CANCELLED; 103 return result; 104 } 105 } 106 107 135 public long scheduledExecutionTime() { 136 synchronized(lock) { 137 return (period < 0 ? nextExecutionTime + period 138 : nextExecutionTime - period); 139 } 140 } 141 } 142 | Popular Tags |