code: private synchronized void waitForCommands(final ActiveContext context) {
      while (!scheduler.hasPendingTasks()) {
        // Wait until any command enters in the queue
        try {
          wait();
        } catch (final InterruptedException e) {
          LOG.log(Level.WARNING, "InterruptedException occurred in SchedulerDriver", e);
        }
      }
      // When wakes up, run the first command from the queue.
      state = State.RUNNING;
      scheduler.submitTask(context);
    }
docs: Pick up a command from the queue and run it. Wait until
  any command coming up if no command exists.