Hi all,

All the while, I am using HttpClient in multithreaded environment. For every 
threads, when they initiate a connection, they will create a complete new 
HttpClient instance.

Recently, I discover, by using this approach, it can cause the user is having 
too many port being opened, and most of the connections are in TIME_WAIT state.

http://www.opensubscriber.com/message/commons-httpclient-...@jakarta.apache.org/86045.html

Hence, instead of per thread doing :
HttpClient c = new HttpClient();
try {
    c.executeMethod(method);
}
catch(...) {
}
finally {
    method.releaseConnection();
}


We plan to have :

[METHOD A]

// global_c is initialized once through
// HttpClient global_c = new HttpClient(new 
MultiThreadedHttpConnectionManager());

try {
    global_c.executeMethod(method);
}
catch(...) {
}
finally {
    method.releaseConnection();
}

In normal situation, global_c will be accessed by 50++ threads concurrently. I 
was wondering, whether this will occur any performance issue? Is 
MultiThreadedHttpConnectionManager using lock-free mechanism to implement its 
thread safe policy?

It is possible if 10 threads are using global_c, will the other 40 threads 
being locked?

Or will it better if in every threads, I create a instance for every 
HttpClient, but release the connection manager explicitly.

[METHOD B]
HttpClient c = new HttpClient();
try {
    c.executeMethod(method);
}
catch(...) {
}
finally {
    method.releaseConnection();
    c.getHttpConnectionManager().shutdown();
}

Is c.getHttpConnectionManager().shutdown() suffer performance issues?

May I know which method (A or B) is better, for application using 50++ threads?

I am using HttpClient 3.1

Thanks and Regards
Yan Cheng Cheok



      

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
For additional commands, e-mail: httpclient-users-h...@hc.apache.org

Reply via email to