You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Dobri Kitipov <kd...@googlemail.com> on 2009/03/19 13:13:17 UTC

Reuse of HTTPClient among different invocations is ok, what about different Web Services, hosts?

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?
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)?

Thank you in advance,
Dobri

Re: Reuse of HTTPClient among different invocations is ok, what about different Web Services, hosts?

Posted by Dobri Kitipov <kd...@googlemail.com>.
Thank you for the fast response Oleg :)
thanks,
dobri

On Thu, Mar 19, 2009 at 3:06 PM, Oleg Kalnichevski <ol...@apache.org> wrote:

> 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
>
>

Re: Reuse of HTTPClient among different invocations is ok, what about different Web Services, hosts?

Posted by Oleg Kalnichevski <ol...@apache.org>.
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