[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[jetty-users] HttpClient.CONNECTOR_SOCKET and QueuedThreadPool in a multi threaded scenario causes application to hang
|
Hi all
I am using Jetty 7.1.2.v20100523 and I am having problems while using HttpClient. In a nut shell, my application is passing an instance of HttpClient to multiple user threads where each thread uses this instance to communicate with the same URL. I am using HttpClient.CONNECTOR_SOCKET and a QueuedThreadPool. My application works only as long as the number of user threads that I am creating is less than the maximum umber of threads in the QueuedThreadPool. The moment number of user threads exceeds maximum number of threads in QueuedThreadPool , my application hangs. When I look in the debugger, I see that all the QueuedThreadPool threads are waiting in HttpConnection.handle method in the this.wait() call. They never seem to be getting notify’ed.
Is this a bug or am I missing something? Am I not supposed to use HttpClient.CONNECTOR_SOCKET in the way I am trying to.
Please refer the following code snippets for a better picture of the problem:
Following is how I am creating an instance of HttpClient in main:
QueuedThreadPool pool = new QueuedThreadPool(4);
pool.setDaemon(true);
pool.setMinThreads(2);
HttpClient jettyClient = new HttpClient();
jettyClient.setConnectorType(HttpClient.CONNECTOR_SOCKET);
jettyClient.setThreadPool(pool);
jettyClient.start();
As you can see, the QueuedThreadPool has maximum of 4 threads and minimum of 2 threads. I then create my user threads:
int numThreads = 20;
Vector<Thread> vThread = new Vector<Thread>();
for(int i=0;i<numThreads;i++){
TestThread t = new TestThread(client);
t.setName("TestThread"+i);
vThread.add(t);
}
for(Thread t:vThread){
t.start();
}
for(Thread t:vThread){
t.join();
}
Following is a snippet from TestThread.run():
ContentExchange exchange = new ContentExchange();
exchange.setMethod("GET");
exchange.setURL("
http://www.yahoo.com");
httpClient.send(exchange); // httpClient is passed while constructing this instance of TestThread
exchange.waitForDone();
byte[] data = "">
System.out.println("Done");
When I run the application, only 3 TestThread's complete. The rest are hung on exchange.waitForDone(). Attaching a debugger shows that the hang is due to the QueuedThreadPool threads waiting to be notified.
Thanks in advance
Sachin
Back to the top