You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Vijay Reddy <rn...@gmail.com> on 2004/09/29 22:36:11 UTC

Concurrent requests to same host

Hi,

I'm using httpClient 2.0.1 stable version on JDK 1.2.2. My class is
coded similar to tutorial example. I've coded static method called
"postData(...)" which instantiates HttpClient and executes the post
method to one perticular URL. The "postData(...)" method/class is
called from a non-Java platform using custom tags.

This seems to be working fine under low loads. But I'm not sure if I'm
using HttpClient package correctly.

Please clarify the following.

1) Do I need to instantiate "HttpClient" only once? (using Singleton).

2) Can I use MultiThreadedHttpConnectionManager in this scenario?
Since I'm hitting only same host all the time, I do not know how to
use this. Could you please give an example. (I want concurrent user
requests executed in multi threading manner. )

Thank you, 
Vijay

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


Re: Concurrent requests to same host

Posted by Oleg Kalnichevski <ol...@apache.org>.
> Please clarify the following.
> 
> 1) Do I need to instantiate "HttpClient" only once? (using Singleton).
> 

You should. There's nothing wrong with having multiple HttpClient
instances, but we generally recommend having only a single one


> 2) Can I use MultiThreadedHttpConnectionManager in this scenario?
> Since I'm hitting only same host all the time, I do not know how to
> use this. Could you please give an example. (I want concurrent user
> requests executed in multi threading manner. )
> 

You must. SimpleHttpConnectionManager used per default is NOT
thread-safe. Regardless how many hosts you intent to hit, you have to
use MultiThreadedHttpConnectionManager when accessing HttpClient from
multiple threads.

For details refer to the HttpClient multithreading guide:

http://jakarta.apache.org/commons/httpclient/threading.html

Hope this helps

Oleg


> Thank you, 
> Vijay
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
> 


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