Issue #3550 - start new thread on execute if there are no idle threads
previously if there were no idle threads, QueuedThreadPool.execute() would just queue the job and not start a new thread to run it Signed-off-by: lachan-roberts <lachlan@webtide.com>
This commit is contained in:
parent
561ea0dafb
commit
f69de3372e
|
@ -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
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue