1 17 package org.apache.servicemix.components.varscheduler; 18 19 import java.util.*; 20 21 26 public abstract class SchedulerTask implements Runnable { 27 28 static final int VIRGIN = 0; 29 static final int SCHEDULED = 1; 30 static final int CANCELLED = 2; 31 32 final Object lock = new Object (); 33 int state = VIRGIN; 34 TimerTask timerTask; 35 36 protected SchedulerTask() { 37 } 38 39 public abstract void run(); 40 41 45 public boolean cancel() { 46 synchronized (lock) { 47 if (timerTask != null) { 48 timerTask.cancel(); 49 } 50 boolean result = (state == SCHEDULED); 51 state = CANCELLED; 52 return result; 53 } 54 } 55 56 public long scheduledExecutionTime() { 57 synchronized (lock) { 58 return timerTask == null ? 0 : timerTask.scheduledExecutionTime(); 59 } 60 } 61 62 } 63 64 | Popular Tags |