Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] How does Jetty thread pool work? QueuedThreadPool is not creating new threads

Just wanted to follow-up to see if someone can throw some light on this? Is it happening due to usage to Async Servlets?

Thanks,
Gaurav


On Thu, Oct 31, 2013 at 7:10 PM, Gaurav Kumar <gauravphoenix@xxxxxxxxx> wrote:
TL;DR - Running embedded Jetty with queuedThreadPool , new threads are not being created 
---

I am using Jetty version 9.0.6.v20130930 in embedded form by starting it as- 

OS is 64 Bit Windows7 and JRE version is  1.7.0_13-b20 (also tested on Linux JRE version 7u25-2.3.10-1ubuntu0.12.04.2 - same behavior is observed)

As you can see, I've set max # of threads to 100 and min to 10. 

I've a monitor thread which prints threadpool status every 1 second. This thread is started just after server.start() method. Here is what I am observing (as soon as server is started and no request has been received by Jetty yet)

queuedThreadPool.getIdleThreads() shows "6" and queuedThreadPool.getThreads() shows "10"

Is this expected? Does it mean that out of 10 threads, 4 threads (10-6) are ready for accepting connection? I think so because thread dump shows 4 threads in Runnable state. 

To process requests, I am using AsyncServlets. My ThreadPoolExecutor for async processing looks like this - 
http://pastebin.com/mM0Vq8LN (core threads -10, max threads -  100) 

When I send requests using apache ab tool, I am setting # of concurrent requests to 100, and total # of requests to 1000. 

Monitor thread of AsyncServlet shows expected result- I can see more threads being created and when all of the requests are finished, threadpool size reducing to core size however, when ab tool is running, I do NOT see ANY change in Jetty thread pool- it still says there are 6 idle threads- looking at JMX info through JConsole confirms same. Here is stacktrace of one of the theads of QTP- 

Name: JettyQTP-36
State: TIMED_WAITING on java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@18dbe927
Total blocked: 2  Total waited: 49,244
Stack trace: 
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:226)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2082)
org.eclipse.jetty.util.BlockingArrayQueue.poll(BlockingArrayQueue.java:390)
org.eclipse.jetty.util.thread.QueuedThreadPool.idleJobPoll(QueuedThreadPool.java:509)
org.eclipse.jetty.util.thread.QueuedThreadPool.access$700(QueuedThreadPool.java:48)
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:563)
java.lang.Thread.run(Thread.java:724)

So the question is - why is Jetty not creating more threads? 

Cheers,
Gaurav








Back to the top