diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java index 1e81258a083..ff18e93eaea 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java @@ -409,7 +409,7 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo private boolean startThreads(int threadsToStart) { - while (threadsToStart > 0) + while (threadsToStart > 0 && isRunning()) { int threads = _threadsStarted.get(); if (threads >= _maxThreads) @@ -561,11 +561,10 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo long now = System.nanoTime(); if (last == 0 || (now - last) > TimeUnit.MILLISECONDS.toNanos(_idleTimeout)) { - shrink = _lastShrink.compareAndSet(last, now) && - _threadsStarted.compareAndSet(size, size - 1); - if (shrink) + if (_lastShrink.compareAndSet(last, now) && _threadsStarted.compareAndSet(size, size - 1)) { - return; + shrink=true; + break loop; } } } @@ -576,9 +575,7 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo finally { if (_threadsIdle.decrementAndGet() == 0) - { startThreads(1); - } } } } @@ -592,8 +589,13 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo } finally { - if (!shrink) - _threadsStarted.decrementAndGet(); + if (!shrink && isRunning()) + { + LOG.warn("Unexpected thread death: {} in {}",this,QueuedThreadPool.this); + // This is an unexpected thread death! + if (_threadsStarted.decrementAndGet()