atom feed2 messages in org.apache.hc.httpclient-usersRe: Using MultiThreadedHttpConnectio...
FromSent OnAttachments
Josh FixSep 26, 2007 12:55 pm 
Roland WeberSep 27, 2007 8:42 am 
Subject:Re: Using MultiThreadedHttpConnectionManager in a Servlet
From:Roland Weber (
Date:Sep 27, 2007 8:42:26 am

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.

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