>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:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>