hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: HttpClent and Threads
Date Thu, 04 Nov 2004 09:14:21 GMT

On Wed, 2004-11-03 at 23:24, No Mojo Mofo wrote:
This is kind of a newbie question
> I've read the bit about using a single HttpClient instance from
> different 
> threads...
> It doesn't say anything about instantiating different instances of
> HttpClent 
> from different threads.  Does this cause problems?  Is HttpClent a 
> singleton?
HttpClient is not a singleton, but usually we do recommend having just
one HttpClient instance per application / component. HttpClient does its
best to reuse persistent connections. Whenever HttpClient instance goes
out of scope all the persistent connections managed by its connection
manager are to be GC-ed as well, which can be quite wasteful. Worse, all
these connections may stay open until they are GC-ed, and it may take
quite a while for the garbage collector to kick in. If you frequently
instantiate HttpClient objects and do not explicitly shut down its
connection manager you may end up with a whole pile of open connections
waiting to be GC-ed.

> If there is no problem with this, what is the expected usage between
> using 
> the MultiThreadedHttpConnectionManager and just instantiating more
> than one 
> HttpClent object for executing different HttpMethods?
It all depends. If you target only one site, and never execute HTTP
methods in parallel, MultiThreadedHttpConnectionManager provides no
benefit compared to the SimpleHttpConnectionManager used per default by

If the connection reuse is important for you, probably you should try to
keep HttpClient instances as long as possible. Otherwise, you can
instantiate a new HttpClient object per request execution.



To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org

View raw message