コード例 #1
0
  @Override
  public List<Runnable> shutdownNow() {
    _mainLock.lock();

    try {
      int state = _runState;

      if (state < _STOP) {
        _runState = _STOP;
      }

      for (WorkerTask workerTask : _workerTasks) {
        workerTask._thread.interrupt();
      }

      List<Runnable> runnables = new ArrayList<Runnable>();

      _taskQueue.drainTo(runnables);

      _tryTerminate();

      return runnables;
    } finally {
      _mainLock.unlock();
    }
  }
コード例 #2
0
  private Runnable _getTask(WorkerTask workerTask, boolean[] cleanUpMarker) {
    while (true) {
      try {
        int state = _runState;

        if (state >= _STOP) {
          return null;
        }

        Runnable runnable = null;

        if (state == _SHUTDOWN) {
          runnable = _taskQueue.poll();
        } else if ((_poolSize > _corePoolSize) || _allowCoreThreadTimeout) {

          runnable = _taskQueue.poll(_keepAliveTime, TimeUnit.NANOSECONDS);
        } else {
          runnable = _taskQueue.take();
        }

        if (runnable != null) {
          return runnable;
        }

        _mainLock.lock();

        try {
          if ((_runState >= _STOP)
              || ((_runState >= _SHUTDOWN) && _taskQueue.isEmpty())
              || (_allowCoreThreadTimeout && ((_poolSize > 1) || _taskQueue.isEmpty()))
              || (!_allowCoreThreadTimeout && (_poolSize > _corePoolSize))) {

            _completedTaskCount += workerTask._localCompletedTaskCount;

            _workerTasks.remove(workerTask);

            if (--_poolSize == 0) {
              _tryTerminate();
            }

            cleanUpMarker[0] = true;

            return null;
          }
        } finally {
          _mainLock.unlock();
        }
      } catch (InterruptedException ie) {
      }
    }
  }
コード例 #3
0
  @Override
  public void shutdown() {
    _mainLock.lock();

    try {
      int state = _runState;

      if (state < _SHUTDOWN) {
        _runState = _SHUTDOWN;
      }

      for (WorkerTask workerTask : _workerTasks) {
        workerTask._interruptIfWaiting();
      }

      _tryTerminate();
    } finally {
      _mainLock.unlock();
    }
  }