public void schedule(TaskRunnable task,Date time) throws IllegalArgumentException, IllegalStateException {
  if (shutdownThePool) {
    throw new IllegalStateException("The timers have been shuted down!");
  }
 else {
    if ((task != null) && (time != null)) {
      HeadTaskRunnable head=null;
      do {
        head=task.getHeadTask();
        if (head != null) {
          if (head.acquireValidLock()) {
            try {
              if (head == task.getHeadTask()) {
                if (head.scheduledExecutionTime() == time.getTime()) {
                  return;
                }
 else {
                  if (!head.isTimedOut()) {
                    throw new IllegalStateException("The task has been scheduled!");
                  }
                }
              }
            }
  finally {
              head.releaseLockAndNotify();
            }
          }
        }
      }
 while (head != task.getHeadTask());
synchronized (taskList) {
        if ((head=(HeadTaskRunnable)taskList.get(time)) == null) {
          task.setNext(null);
          taskList.put(time,new HeadTaskRunnable(this,task,time));
        }
      }
      if (head == null) {
synchronized (this) {
          if ((nextRun == null) || (time.getTime() < nextRun.getTime())) {
            nextRun=time;
            long delay=time.getTime() - currentTimeMillis();
            scheduler.setWait(((delay < 0) ? 0 : delay));
          }
        }
      }
 else {
        if (head.acquireValidLock()) {
          try {
            task.setHeadTask(head);
            TaskRunnable tailTask=head.tail();
            task.setPrevious(tailTask);
            tailTask.setNext(task);
            task.setNext(null);
            head.setTail(task);
          }
  finally {
            head.releaseLockAndNotify();
          }
        }
 else {
          schedule(task,time);
        }
      }
    }
 else {
      throw new IllegalArgumentException();
    }
  }
}

public void schedule ( TaskRunnable task , Date time ) throws IllegalArgumentException , IllegalStateException { if ( shutdownThePool ) { throw new IllegalStateException ( "The timers have been shuted down!" ) ; } else { if ( ( task != null ) && ( time != null ) ) { HeadTaskRunnable head = null ; do { head = task . getHeadTask ( ) ; if ( head != null ) { if ( head . acquireValidLock ( ) ) { try { if ( head == task . getHeadTask ( ) ) { if ( head . scheduledExecutionTime ( ) == time . getTime ( ) ) { return ; } else { if ( ! head . isTimedOut ( ) ) { throw new IllegalStateException ( "The task has been scheduled!" ) ; } } } } finally { head . releaseLockAndNotify ( ) ; } } } } while ( head != task . getHeadTask ( ) ) ; synchronized ( taskList ) { if ( ( head = ( HeadTaskRunnable ) taskList . get ( time ) ) == null ) { task . setNext ( null ) ; taskList . put ( time , new HeadTaskRunnable ( this , task , time ) ) ; } } if ( head == null ) { synchronized ( this ) { if ( ( nextRun == null ) || ( time . getTime ( ) < nextRun . getTime ( ) ) ) { nextRun = time ; long delay = time . getTime ( ) - currentTimeMillis ( ) ; scheduler . setWait ( ( ( delay < 0 ) ? 0 : delay ) ) ; } } } else { if ( head . acquireValidLock ( ) ) { try { task . setHeadTask ( head ) ; TaskRunnable tailTask = head . tail ( ) ; task . setPrevious ( tailTask ) ; tailTask . setNext ( task ) ; task . setNext ( null ) ; head . setTail ( task ) ; } finally { head . releaseLockAndNotify ( ) ; } } else { schedule ( task , time ) ; } } } else { throw new IllegalArgumentException ( ) ; } } }
schedules a taskrunnable to the timerpool .
