hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roland Weber <ROLWE...@de.ibm.com>
Subject Re: Is this a good idea?
Date Fri, 09 Feb 2007 06:13:52 GMT
Hello Steve,

>    I think I am losing an argument at work. A coworker is implementing
> some code that will be used to call a servlet. HttpClient is the tool of
> choice, of course. The code he is writing must handle multiple requests
> in parallel, thus he will be using the MultiThreadedConnectionManager.
> However, he is proposing to channel all his requests through a
> singleton. 

This is exactly how HttpClient is supposed to be used. Each thread
that calls the singleton HttpClient will get it's own connection from
the MTHCM (assuming the connection limits are chosen appropriately).
MTHCM is internally synchronized.
You only have to take care about HttpState. HttpClient holds a single
default HttpState, which is also synchronized internally. If it's OK
for all the threads to share one state, that's fine. Otherwise, each
thread has to keep it's own HttpState and pass it to execute().

hope that helps,

View raw message