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 d15d2c19a55..9cacfca2f31 100755 --- 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 @@ -474,7 +474,7 @@ public class QueuedThreadPool extends ContainerLifeCycle implements SizedThreadP else { // Make sure there is at least one thread executing the job. - if (getThreads() == 0) + if (getQueueSize() > 0 && getIdleThreads() == 0) startThreads(1); } } @@ -781,8 +781,11 @@ public class QueuedThreadPool extends ContainerLifeCycle implements SizedThreadP } job = idleJobPoll(); - if (job==SHRINK) + if (job == SHRINK) + { + LOG.warn("shrinking {}", this); break; + } } // run job diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java index 0199c7f0171..45711f94acf 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java @@ -167,6 +167,39 @@ public class QueuedThreadPoolTest extends AbstractThreadPoolTest waitForIdle(tp,2); } + @Test + public void testExecuteNoIdleThreads() throws Exception + { + QueuedThreadPool tp= new QueuedThreadPool(); + tp.setDetailedDump(true); + tp.setMinThreads(3); + tp.setMaxThreads(10); + tp.setIdleTimeout(500); + + tp.start(); + + RunningJob job1 = new RunningJob(); + tp.execute(job1); + + RunningJob job2 = new RunningJob(); + tp.execute(job2); + + RunningJob job3 = new RunningJob(); + tp.execute(job3); + + // make sure these jobs have started running + assertTrue(job1._run.await(5, TimeUnit.SECONDS)); + assertTrue(job2._run.await(5, TimeUnit.SECONDS)); + assertTrue(job3._run.await(5, TimeUnit.SECONDS)); + + waitForThreads(tp, 4); + waitForThreads(tp, 3); + + RunningJob job4 = new RunningJob(); + tp.execute(job4); + assertTrue(job4._run.await(5, TimeUnit.SECONDS)); + } + @Test public void testLifeCycleStop() throws Exception {