protected void finalize() throws Throwable { synchronized(queue) { thread.newTasksMayBeScheduled = false; thread.notifyQueue(1); // In case queue is empty. } } };
protected void finalize() throws Throwable { synchronized(queue) { thread.newTasksMayBeScheduled = false; thread.notifyQueue(1); // In case queue is empty. } } };
/** * Terminates this timer, discarding any currently scheduled tasks. * Does not interfere with a currently executing task (if it exists). * Once a timer has been terminated, its execution thread terminates * gracefully, and no more tasks may be scheduled on it. * * <p>Note that calling this method from within the run method of a * timer task that was invoked by this timer absolutely guarantees that * the ongoing task execution is the last task execution that will ever * be performed by this timer. * * <p>This method may be called repeatedly; the second and subsequent * calls have no effect. */ public void cancel() { synchronized(queue) { thread.newTasksMayBeScheduled = false; queue.clear(); thread.notifyQueue(1); // In case queue was already empty. } }
/** * Terminates this timer, discarding any currently scheduled tasks. * Does not interfere with a currently executing task (if it exists). * Once a timer has been terminated, its execution thread terminates * gracefully, and no more tasks may be scheduled on it. * * <p>Note that calling this method from within the run method of a * timer task that was invoked by this timer absolutely guarantees that * the ongoing task execution is the last task execution that will ever * be performed by this timer. * * <p>This method may be called repeatedly; the second and subsequent * calls have no effect. */ public void cancel() { synchronized(queue) { thread.newTasksMayBeScheduled = false; queue.clear(); thread.notifyQueue(1); // In case queue was already empty. } }
thread.notifyQueue(1);
@Override public void run() { try { mainLoop(1); } finally { synchronized (queue) { if (!queue.isEmpty()) { long next = queue.getMin().nextExecutionTime; long now = System.currentTimeMillis(); int delta = (int) (next - now); notifyQueue(delta); } } } // try { // mainLoop(0); // } finally { // // Someone killed this Thread, behave as if Timer cancelled // synchronized(queue) { // newTasksMayBeScheduled = false; // queue.clear(); // Eliminate obsolete references // } // } }
@Override public void run() { try { mainLoop(1); } finally { synchronized (queue) { if (!queue.isEmpty()) { long next = queue.getMin().nextExecutionTime; long now = System.currentTimeMillis(); int delta = (int) (next - now); notifyQueue(delta); } } } // try { // mainLoop(0); // } finally { // // Someone killed this Thread, behave as if Timer cancelled // synchronized(queue) { // newTasksMayBeScheduled = false; // queue.clear(); // Eliminate obsolete references // } // } }
notifyQueue((int)(executionTime - currentTime)); return;
notifyQueue((int)(executionTime - currentTime)); return;