Oleg and Ortwin,

On Mon, Jun 15, 2009 at 4:07 PM, Oleg Kalnichevski <[email protected]> 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?

Could I just declare a static MultiThreadedHttpConnectionManager in a
Servlet, statically set the parameters to initialize it and then use it like
this:

        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?


> 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.  Could I just call
closeIdleConnections() every once in a while to do some cleanup?

>
> 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.

I greatly appreciate everyone's help,
David Hamilton

Reply via email to