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:
parent
06e1252a6f
commit
a01e4a0f49
|
@ -75,7 +75,7 @@ public class QueuedThreadPool extends ContainerLifeCycle implements SizedThreadP
|
||||||
|
|
||||||
public QueuedThreadPool(@Name("maxThreads") int maxThreads)
|
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)
|
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)
|
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);
|
setMinThreads(minThreads);
|
||||||
setMaxThreads(maxThreads);
|
setMaxThreads(maxThreads);
|
||||||
setIdleTimeout(idleTimeout);
|
setIdleTimeout(idleTimeout);
|
||||||
|
|
|
@ -302,4 +302,10 @@ public class QueuedThreadPoolTest
|
||||||
|
|
||||||
assertTrue(latch.await(5, TimeUnit.SECONDS));
|
assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testConstructorMinMaxThreadsValidation()
|
||||||
|
{
|
||||||
|
new QueuedThreadPool(4, 8);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue