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/[email protected]/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]
MultiThreadedHttpConnectionManager connman = new MultiThreadedHttpConnectionManager();
HttpClient c = new HttpClient(connman);
try {
c.executeMethod(method);
}
catch(...) {
}
finally {
method.releaseConnection();
connman.shutdown();
}
Is connman.shutdown() suffer performance issues?
May I know which method (A or B) is better, for application using 50++ threads?