commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rodney Waldhoff" <rw...@hotmail.com>
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 
parallel.

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();
conn.open();
method.execute(state,conn);
conn.close();
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: 
http://photos.msn.com/support/worldwide.aspx


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


Mime
View raw message