commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rodney Waldhoff" <>
Subject Re: HTTPClient thread-safe?
Date Mon, 17 Dec 2001 13:41:50 GMT
>Is HTTP Client (and HTTPClient class in particular) thread-safe?

Yes and no.

The HTTP Client package can be used to execute many http requests in 

The HttpClient class in particular cannot be used to execute many http 
requests in parallel.

Currently the HttpClient class maintains a single HttpConnection (i.e, a 
single socket connection to a web server), so that class is not well suited 
for running multiple http requests in parallel.

But remember that you don't need to use the HttpClient class at all.  Paul's 
right, if you want to make mulitple http requests in parallel, just use 
HttpMethod/HttpConnection instances directly:

Here's a simple, single threaded example:

HttpConnection conn = new HttpConnection("host",port);
HttpMethod method = new GetMethod("/path/file.html");
HttpState state = new HttpState();;
String response = method.getResponseBodyAsString();

Multiple method/connection/state triplets should be perfectly safe to run in 
parallel. If you'd like to share HttpState between parallel methods, there's 
a little more work to do--but you could subclass HttpState to synchronize 
its methods.

- Rod

MSN Photos is the easiest way to share and print your photos:

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message