if (task.period > 0) { task.setTimeToRun(now + task.period); heap_.insert(task); }  return task; } } } } } catch (InterruptedException ex) {  }
if (task.period > 0) { task.setTimeToRun(now + task.period); heap_.insert(task); }
  protected synchronized TaskNode nextTask() {    // Note: This code assumes that there is only one run loop thread    try {      while (!Thread.interrupted()) {        // Using peek simplifies dealing with spurious wakeups        TaskNode task = (TaskNode)(heap_.peek());        if (task == null) {          wait();        }        else  {          long now = System.currentTimeMillis();          long when = task.getTimeToRun();          if (when > now) { // false alarm wakeup            wait(when - now);          }          else {            task = (TaskNode)(heap_.extract());            if (!task.getCancelled()) { // Skip if cancelled by              if (task.period > 0) {  // If periodic, requeue                 task.setTimeToRun(now + task.period);                heap_.insert(task);              }                            return task;            }          }        }      }    }    catch (InterruptedException ex) {  } // fall through    return null; // on interrupt  }