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 3541f1c4708..fd254cade8f 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 @@ -75,7 +75,7 @@ public class QueuedThreadPool extends ContainerLifeCycle implements SizedThreadP public QueuedThreadPool(@Name("maxThreads") int maxThreads) { - this(maxThreads, 8); + this(maxThreads, Math.min(8, maxThreads)); } public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads) @@ -100,6 +100,11 @@ public class QueuedThreadPool extends ContainerLifeCycle implements SizedThreadP public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads, @Name("idleTimeout") int idleTimeout, @Name("reservedThreads") int reservedThreads, @Name("queue") BlockingQueue queue, @Name("threadGroup") ThreadGroup threadGroup) { + if (maxThreads < minThreads) { + throw new IllegalArgumentException("max threads ("+maxThreads+") less than min threads (" + +minThreads+")"); + } + setMinThreads(minThreads); setMaxThreads(maxThreads); setIdleTimeout(idleTimeout); 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 61a2df76334..fff2e15b7d9 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 @@ -302,4 +302,10 @@ public class QueuedThreadPoolTest assertTrue(latch.await(5, TimeUnit.SECONDS)); } + + @Test(expected = IllegalArgumentException.class) + public void testConstructorMinMaxThreadsValidation() + { + new QueuedThreadPool(4, 8); + } }