D H wrote:
> Oleg and Ortwin,
>
> On Mon, Jun 15, 2009 at 4:07 PM, Oleg Kalnichevski <
olegk@...> wrote:
>
>> David,
>>
>> Another big issue is that a new instance of HttpClient is created for each
>> new request. This is enormously wasteful, as every time there likely to be
>> an open connection going out of scope, which needs to be GC-ed in order to
>> free up system resources.
>
>
> Thank you for all of the advice, I've been talking with my boss quite a bit
> and he wants me to document the best practices for HttpClient so that we can
> have the developers fix the problems with their code. The application is a
> website that uses well over a hundred different URLs. I found a
> MultiThreadedExample at
>
http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/MultiThreadedExample.java?revision=608014but> it looks like you have to declare all of the URLs that it is going to
> use?
>
No, you certainly do not have to.
> Could I just declare a static MultiThreadedHttpConnectionManager in a
> Servlet, statically set the parameters to initialize it and then use it like
> this:
>
You will be much better off using ServletContextListener to create and
shut down MultiThreadedHttpConnectionManager and ServletContext to store
the reference to that instance.
> HttpClient client = new HttpClient(connectionManager);
> PostMethod post = new PostMethod(inUrl);
> try {
> post.setRequestEntity(new StringRequestEntity(inPayload, null,
> null));
> int statusCode = client.executeMethod(post);
> payload = SlowUtilities.readPayload(post);
> } finally {
> post.releaseConnection();
> }
>
> Or do you recommend using the SimpleHttpConnectionManager for situations
> like ours?
>
One should definitely use MultiThreadedHttpConnectionManager in a
servlet container.
>
>> You should re-use HttpClient instance for multiple request and shut down
>> its connection manager when it is no longer used.
>>
>
> I'm not sure when the connection manager would be shut down though, this is
> a 24/7 application for a medical center and really only goes down when this
> slowdown problem occurs that renders the site unusable.
ServletContextListener is your friend.
Could I just call
> closeIdleConnections() every once in a while to do some cleanup?
Yes, you should.
>
>> Besides, upgrading to Httpclient 4.0 may be a big jump, but there is no
>> excuse for not upgrading to HttpClient 3.1
>>
> I'm working on getting them to agree to upgrade to HttpClient 3.1. The
> application depends on a lot of different libraries so I don't know how
> easily they could upgrade to HttpClient 4.0 but I'll look into it.
>
HttpClient 4.0 is _massively_ better than 3.x version and is better
documented. You should tell your boss to seriously consider upgrading.
Besides, 3.x code line is effectively at the end of life.
It is just a matter of time I _personally_ will stop answering any
questions about HttpClient 3.x
Cheers
Evil Comrade Oleg
> I greatly appreciate everyone's help,
> David Hamilton
>
---------------------------------------------------------------------
To unsubscribe, e-mail:
dev-unsubscribe@...
For additional commands, e-mail:
dev-help@...