code: public void cancel() {
      lock.lock();
      try {
        thread.newTasksMayBeScheduled = false;
        queue.clear();
        condition.signal();
        if (reachedJob != null) {
          clock.disableJob(reachedJob);
        }
      } finally {
        lock.unlock();
      }
    }
docs: 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.