code: private void sched(TimerTask task, long time, long period) {
          if (time < 0)
              throw new IllegalArgumentException("Illegal execution time.");
  
          // Constrain value of period sufficiently to prevent numeric
          // overflow while still being effectively infinitely large.
          if (Math.abs(period) > (Long.MAX_VALUE >> 1))
              period >>= 1;
  
          synchronized(queue) {
              if (!thread.newTasksMayBeScheduled)
                  throw new IllegalStateException("Timer already cancelled.");
  
              synchronized(task.lock) {
                  if (task.state != TimerTask.VIRGIN)
                      throw new IllegalStateException(
                          "Task already scheduled or cancelled");
                  task.nextExecutionTime = time;
                  task.period = period;
                  task.state = TimerTask.SCHEDULED;
              }
  
              queue.add(task);
              if (queue.getMin() == task)
                  queue.notify();
          }
      }
docs: Schedule the specified timer task for execution at the specified
  time with the specified period, in milliseconds.  If period is
  positive, the task is scheduled for repeated execution; if period is
  zero, the task is scheduled for one-time execution. Time is specified
  in Date.getTime() format.  This method checks timer state, task state,
  and initial execution time, but not period.
  
  @throws IllegalArgumentException if <tt>time</tt> is negative.
  @throws IllegalStateException if task was already scheduled or
  cancelled, timer was cancelled, or timer thread terminated.
  @throws NullPointerException if {@code task} is null