private void startWorkPackage(final WorkPackage workPackage) {
    workPackage.start();

    for (final Work work : workPackage.getWorkList()) {
      executor.execute(
          new Runnable() {
            @Override
            public void run() {
              try {
                work.executeWork();
              } finally {
                workCompleted(work, workPackage);
              }
            }
          });
    }
  }
  public synchronized void doWork(final WorkPackage workPackage) {
    int threads = 1; // Manager.get().getEngineSettings().getThreads();
    if (currentStatus == StatusType.idle || pool != threads) {
      pool = threads;
      executor = createExecutor();
    }

    if (workPackage.getWorkList().isEmpty()) {
      return;
    }

    setCurrentStatusAndNotifyListenerIfTypeChanged(StatusType.working);

    workRemaining += workPackage.getWorkList().size();

    startWorkPackage(workPackage);
  }
  private synchronized void workCompleted(Work work, WorkPackage workPackage) {
    workRemaining--;
    workPackage.completedWork(work);

    if (workRemaining < 0) {
      throw new IllegalStateException("Remaining work = " + workRemaining);
    } else if (workRemaining == 0) {
      setCurrentStatusAndNotifyListenerIfTypeChanged(StatusType.idle);
      executor.shutdown();
      executor = null;
    }
  }