qtp constructor min-max validation

When min and max threads are passed together, verify
max >= min to detect bad configuration.

Signed-off-by: David Ha <davidha@1493.net>
This commit is contained in:
David Ha 2018-01-31 23:29:22 -05:00
parent 06e1252a6f
commit a01e4a0f49
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);
}
}