Exemple #1
0
  public boolean assign(Runnable work, boolean addToQueueIfFull) {
    if (this.stopThePool) {
      throw new RuntimeException("Pool is stopping... no more work please.");
    }
    Work runWork = new Work(work);

    PooledThread thread = getNextAvailableThread();
    if (thread != null) {
      this.busyList.add(thread);
      thread.assignWork(runWork);
      return true;
    }
    if (addToQueueIfFull) {
      runWork.setEnterQueueTime(System.currentTimeMillis());
      this.workOverflowQueue.add(runWork);
    }
    return false;
  }