/** * Check whether the work got rescheduled */ private synchronized void endRun() { running = false; if (reschedule == true) timeout = scheduler.add(this); reschedule = false; }
/** * Set the scheduler for this runnable * * @param scheduler pass null to remove the runnable from any scheduler * @return the previous scheduler or null if there was no previous scheduler */ public synchronized RunnableScheduler setScheduler(RunnableScheduler scheduler) { // Null operation if (this.scheduler == scheduler) return this.scheduler; // Remember the result RunnableScheduler result = this.scheduler; // Remove from previous scheduler if (this.timeout != null) timeout.cancel(); // Set the new state this.scheduler = scheduler; // This is a remove operation if (scheduler == null) reschedule = false; // If we are not running, add it to the scheduler otherwise // remember we want adding else if (running == false) timeout = scheduler.add(this); else reschedule = true; // We are done return result; }
/** * Sets the next run date<p> * * If it is linked to a scheduler, it is temporarily removed while the date * is modified. * * @param nextRun the next run date */ public synchronized void setNextRun(long nextRun) { // Remove from scheduler if (timeout != null) timeout.cancel(); // Set the new run time this.nextRun.set(nextRun); // If we are not running, add it to the scheduler otherwise // remember we want adding back if (running == false && scheduler != null) { //log.debug("add to scheduler: " + this); timeout = scheduler.add(this); } else { //log.debug("reschedule: " + this); reschedule = true; } }