@Override public void run() { executeTasksWhileRunning(); synchronized (workerPool.workerStopNotifyLock) { workerPool.workerStopNotifyLock.notifyAll(); } } }
if (shutdownFinishing) { currentPoolSize.decrementAndGet(); worker.stopIfRunning(); return null; } else if ((casPoolSize = currentPoolSize.get()) > maxPoolSize) { if (currentPoolSize.compareAndSet(casPoolSize, casPoolSize - 1)) { worker.stopIfRunning(); return null;
if (shutdownFinishing) { currentPoolSize.decrementAndGet(); worker.stopIfRunning(); return null; } else if ((casPoolSize = currentPoolSize.get()) > maxPoolSize) { if (currentPoolSize.compareAndSet(casPoolSize, casPoolSize - 1)) { worker.stopIfRunning(); return null;
@Test public void workerIdleTest() { final Worker w = new Worker(workerPool, workerPool.threadFactory); w.start(); // wait for worker to become idle new TestCondition(() -> workerPool.idleWorker.get(), (o) -> o == w).blockTillTrue(); workerPool.startShutdown(); workerPool.finishShutdown(); // verify idle worker is gone new TestCondition(() -> workerPool.idleWorker.get() == null).blockTillTrue(); // should return immediately now that we are shut down workerPool.workerIdle(new Worker(workerPool, workerPool.threadFactory)); } }
@Override public void run() { executeTasksWhileRunning(); synchronized (workerPool.workerStopNotifyLock) { workerPool.workerStopNotifyLock.notifyAll(); } } }
protected void executeTasksWhileRunning() { while (isRunning()) { TaskWrapper nextTask = workerPool.workerIdle(this); if (nextTask != null) { // may be null if we are shutting down nextTask.runTask(); } } }
/** * This call creates and starts a new worker. It does not modify {@link currentPoolSize} so * that MUST be updated in a thread safe way before this is invoked. As soon as the worker * starts it will attempt to start taking tasks, no further action is needed. */ protected void makeNewWorker() { Worker w = new Worker(this, threadFactory); w.start(); }
protected void executeTasksWhileRunning() { while (isRunning()) { TaskWrapper nextTask = workerPool.workerIdle(this); if (nextTask != null) { // may be null if we are shutting down nextTask.runTask(); } } }
/** * This call creates and starts a new worker. It does not modify {@link currentPoolSize} so * that MUST be updated in a thread safe way before this is invoked. As soon as the worker * starts it will attempt to start taking tasks, no further action is needed. */ protected void makeNewWorker() { Worker w = new Worker(this, threadFactory); w.start(); }