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 Antonio Sánchez <in...@gmail.com> on 2010/10/06 23:21:18 UTC
Multithreaded http client application: how-to?
Hi.
I'm developing a Swing client application for requesting a web
application (Struts2).
This client application is required to deal with concurrent requests
(SwingWorkers) that will finally be performed using HttpClient4.
All request will have the same URL: "http://www.myhost.com/mywebapp",
only query string will change:
"http://www.myhost.com/mywebapp/myrequest?myparam=myvalue".
The application must be session aware (JSESSIONID cookie) and possibly
will require to generally manage some other HTTP state.
My questions:
1. Should I share the same HttpClient instance for all requests
(concurrent or not)? Or should I instantiate a new HttpClient for every
new request (concurrent or not)?
2. Should I use a 'ThreadSafeClientConnManager as stated in
http://hc.apache.org/httpcomponents-client-4.0.3/tutorial/html/connmgmt.html#d4e629 ? Or using a new HttpClient instance for every concurrent request is enough?
Thanks and regards.
Antonio.
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Multithreaded http client application: how-to?
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2010-10-14 at 09:20 -0700, Antonio Sanchez wrote:
> Thanks Oleg.
>
>
> olegk wrote:
> >
> > You should be re-using the same instance of HttpClient
> >
>
> Do I need to synchronize access to the HttpClient instance?
>
No, you do not. DefaultHttpClient is fully thread-safe *as long as* all
dependent interface implementations (connection manager, auth handlers,
redirect strategy, keep alive strategy and so on) injected by the user
are thread-safe.
>
> olegk wrote:
> >
> > You should be using the same instance of pooling connection manager such
> > as ThreadSafeClientConnManager for all requests.
> >
>
> How does ThreadSafeClientConnManager work? Does it just synchronize the
> management of internal connection resources? Or does it behaves in a true
> concurrent fashion having multiple transfers at the very same time though my
> one HttpClient instance?
>
It is the latter. Feel free to review the source, though, to form an
opinion.
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Multithreaded http client application: how-to?
Posted by Antonio Sanchez <in...@gmail.com>.
Thanks Oleg.
olegk wrote:
>
> You should be re-using the same instance of HttpClient
>
Do I need to synchronize access to the HttpClient instance?
olegk wrote:
>
> You should be using the same instance of pooling connection manager such
> as ThreadSafeClientConnManager for all requests.
>
How does ThreadSafeClientConnManager work? Does it just synchronize the
management of internal connection resources? Or does it behaves in a true
concurrent fashion having multiple transfers at the very same time though my
one HttpClient instance?
--
View this message in context: http://old.nabble.com/Multithreaded-http-client-application%3A-how-to--tp29900978p29964141.html
Sent from the HttpClient-User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Multithreaded http client application: how-to?
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2010-10-06 at 23:21 +0200, Antonio Sánchez wrote:
> Hi.
>
> I'm developing a Swing client application for requesting a web
> application (Struts2).
>
> This client application is required to deal with concurrent requests
> (SwingWorkers) that will finally be performed using HttpClient4.
>
> All request will have the same URL: "http://www.myhost.com/mywebapp",
> only query string will change:
> "http://www.myhost.com/mywebapp/myrequest?myparam=myvalue".
>
> The application must be session aware (JSESSIONID cookie) and possibly
> will require to generally manage some other HTTP state.
>
> My questions:
>
> 1. Should I share the same HttpClient instance for all requests
> (concurrent or not)? Or should I instantiate a new HttpClient for every
> new request (concurrent or not)?
>
You should be re-using the same instance of HttpClient
> 2. Should I use a 'ThreadSafeClientConnManager as stated in
> http://hc.apache.org/httpcomponents-client-4.0.3/tutorial/html/connmgmt.html#d4e629 ? Or using a new HttpClient instance for every concurrent request is enough?
>
You should be using the same instance of pooling connection manager such
as ThreadSafeClientConnManager for all requests.
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org