public synchronized void dispose() {
    List<SchedulerListener> l = listeners;
    listeners = null;

    if (l != null) {
      boolean cont = true;
      while (cont) {
        synchronized (l) {
          int queueSize = getQueueSize();
          if (queueSize == 0) {
            cont = false;
          } else {
            try {
              l.wait();
            } catch (InterruptedException ex) {
              // Ignore!
            }
          }
        }
      }

      synchronized (l) {
        l.clear();
      }
    }
  }
 public void removeSchedulerListener(SchedulerListener schedulerListener) {
   if (schedulerListener != null) {
     List<SchedulerListener> l = listeners;
     if (l != null) {
       synchronized (l) {
         l.remove(schedulerListener);
       }
     }
   }
 }
 public void addSchedulerListener(SchedulerListener schedulerListener) {
   if (schedulerListener != null) {
     List<SchedulerListener> l = listeners;
     if (l != null) {
       synchronized (l) {
         l.add(schedulerListener);
       }
     }
   }
 }