hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roland Weber <ossf...@dubioso.net>
Subject Re: Using MultiThreadedHttpConnectionManager in a Servlet
Date Thu, 27 Sep 2007 15:42:26 GMT
Hello Josh,

Josh Fix wrote:
> Is it possible to have multiple threads from my servlet
> open simultaneous connections to an external web site with
> different requests and read the results?
Sure. That's what the MultiThreadedHttpConnectionManager
is there for.
> I would really like to get around the blocking aspect of
> the read statements.

What are your settings for the connections-per-host and
total-connections limits? Default for CPH is 2, as that
is mentioned in RFC 2616. Since you're operating some
kind of proxy agent, you are entitled to use 2 per client
for which your servlet is acting.
http://jakarta.apache.org/httpcomponents/httpclient-3.x/threading.html

> My servlet declares the MTHCM as a static object in the
> servlet class, so that once instance is shared amongst all
> incoming servlet requests, and a static{} block is used in
> the class to set timeouts/etc.

Bad style, but probably irrelevant for the problem at hand.
You should declare shared objects as non-static attributes of
the servlet and initialize them in the Servlet.init() method.

> The HttpClient is newed in the doGet method.

Unless you need different parameters for the instances,
that is not a good idea. Use one client object and set
specific parameters at the method you are executing.
Our preferences hierarchies do not respond well to using
multiple clients with the same MTHCM. There can be only
one parent to the connection manager params.

hope that helps,
  Roland


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


Mime
View raw message