code: private synchronized void mainLoop() {
          for (Task task: taskDao.listTasks()) {
              if (task.getState().equals(Task.STARTING)) {
                  startTask(task);
              } else if (task.getState().equals(Task.PAUSING)) {
                  pauseTask(task);
              } else if (task.getState().equals(Task.RESUMING)) {
                  resumeTask(task);
              } else if (task.getState().equals(Task.CANCELING)) {
                  cancelTask(task);
              }
          }
          try {
              wait(POLL_SECONDS * 1000);
          } catch (InterruptedException e) {
          }
      }
docs: Main loop -- Task State Transition