[jetty-dev] [jira] (JETTY-1527) QueuedThreadPool Anomaly

"David Wade (JIRA)" <[email protected]> Wed, 20 Jun 2012 18:24:21 -0500 (CDT)
Newsgroups gmane.comp.java.jetty.general
Message-ID <1869074829.14551.1340234661066.JavaMail.j2ee-jira@codehaus01.managed.contegix.com>
David Wade
created JETTY-1527

QueuedThreadPool Anomaly

Issue Type:

Bug

Assignee:

Unassigned

Attachments:

ContrivedQueuedThreadPoolTest.java

Created:

20/Jun/12 6:24 PM

Description:

Under a quite contrived unit test scenario, discovered that the QueuedThreadPool thread pool in Jetty util can be reluctant to grow when it should....

In the attached very contrived unit test, a pool is configured with a maximum of 50 threads. The test then creates ten runables which are given to the pool to execute. However, only the first nine of those runnables actually start running and so the test will fail at the following assert:-

Assert.assertEquals(testThreadsRunning, TEST_THREADS);

The tenth runnable is left in the queue until such time as a thread returns to the pool (which in this contrived test, they don't).

In normal running, there are continually threads being put back into the pool such that if the pool should have/could have grown, a request doesn't normally have to wait long to get picked up.

I think the pool here is too reluctant to grow which means that sometimes requests in Jetty maybe subject to addition latency in processing.

I think the fix is to move a couple of lines in the dispatch method, but I don't know if this might make the pool to eager to grow....

public boolean dispatch(Runnable job)

{

if (isRunning())

{

if (_jobs.offer(job))

{

final int jobQ = _jobs.size();

final int idle = getIdleThreads();

// If we had no idle threads or the jobQ is greater than the idle threads

if (idle == 0 || jobQ > idle)

{
int threads = _threadsStarted.get();
if (threads <= _maxThreads)
startThread(threads);
}

return true;

}

else

{

LOG.debug("Declined {} on {}", job, this);

}

}

LOG.debug("Dispatched {} to stopped {}", job, this);

return false;

}

Project:

Jetty

Priority:

Minor

Reporter:

David Wade

This message is automatically generated by JIRA.

If you think it was sent incorrectly, please contact your JIRA administrators .

For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email