Issue #2171 QueuedThreadPool min/max threads validation

Now throwing IllegalArgumentException in case max < min.
This commit is contained in:
Simone Bordet 2018-02-08 22:22:14 +01:00 committed by GitHub
commit e87775eb0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -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<Runnable> 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);

View File

@ -302,4 +302,10 @@ public class QueuedThreadPoolTest
assertTrue(latch.await(5, TimeUnit.SECONDS));
}
@Test(expected = IllegalArgumentException.class)
public void testConstructorMinMaxThreadsValidation()
{
new QueuedThreadPool(4, 8);
}
}