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: Reuse of HTTPClient among different invocations is ok, what about different Web Services, hosts?
Date Thu, 19 Mar 2009 13:06:26 GMT
On Thu, 2009-03-19 at 14:13 +0200, Dobri Kitipov wrote:
> Hi everybody,
> when we reuse HTTPClient underneath each subsequent call to
> HttpClient.executeMethod() will go to the connection manager
> (MultiThreadedHttpConnectionManager) and ask for an instance of
> HttpConnection. I have tested some use cases when a HTTPClient is reused for
> invocation of a single WS and I can verify there is socket reuse. So far so
> good.
> 
> Anyway, my question is: could we expect any problems when reusing HTTPClient
> among different threads calling different WSs which are deployed at
> different hosts/servers?

HttpClient is fully thread-safe when used with a thread-safe connection
manager.


> As stated at - http://hc.apache.org/httpclient-3.x/threading.html - there is
> a test case that demonstrates how HTTPClient can be reused among different
> threads which in turn invoke different web services (WSs). My concern is
> that HTTPClient has HttpState which I am not sure could be reused/shared
> among different WSs invocations (JavaDoc says for HttpState: "A container
> for HTTP attributes that may persist from request to request, such as {@link
> Cookie cookies} and authentication {@link Credentials credentials}.")? Can
> different WS clients share one HttpClient and its HttpState among different
> threads and invoking different WSs (e.g. at differnet hosts)?
> 

Yes, they can. Maintain a separate instance of HttpState per execution
thread and pass it as a parameter to the HttpClient#executeMethod

Hope this helps

Oleg 


> Thank you in advance,
> Dobri


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


Mime
View raw message