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();
      }
    }
  }