[prev in list] [next in list] [prev in thread] [next in thread]
List: httpclient-users
Subject: Re: Releasing Connection
From: Matt Narrell <matt.narrell () gmail ! com>
Date: 2012-02-01 0:20:32
Message-ID: E2B57044-ADAC-4769-8818-A1194C6F3404 () gmail ! com
[Download RAW message or body]
Releasing the connection is managed by the aptly named ConnectionManager. Consuming \
the entity (ultimately closing the InputStream) indicates that your usage of the \
current connection is complete. The ConnectionManager will then decide what to do \
with the connection. Read section 2.2 of [2] where connection persistence is \
discussed. It's highly likely that your ConnectionManager is keeping this connection \
open for future requests.
If you must have the connection released, take a look at setting a \
ConnectionKeepAliveStrategy on the HttpClient. Set the KeepAliveDuration to -1, and \
ensure you clean up your entities.
mn
On Jan 31, 2012, at 9:07 AM, Mohit Anchlia wrote:
> On Tue, Jan 31, 2012 at 8:24 AM, Matt Narrell <matt.narrell@gmail.com> wrote:
> > You must consume the HttpEntity in every case, even if there is an exception, or \
> > you will leak connections from your ConnectionManager's pool.
> > You can consume entities via:
> >
> > * Calling any of the EntityUtils.* methods.
>
> But from looking at the code it looks like thatr
> "EntityUtils.toByteArray(entity), " also closes the stream. Does that
> release connection?
> > * Using a org.apache.http.impl.client.BasicResponseHandler (or any \
> > org.apache.http.client.ResponseHandler implementation that consumes the \
> > HttpEntity).
> > * Calling abort() on the HttpUriRequest in case of an exception.
> > See [1] for more information.
> >
> > Do not call releaseConnection explicitly (unless you're implementing a \
> > ConnectionManager or working at low levels). Doing so may conflict with any \
> > Keep-Alive strategies or connection persistence you might use. See [2], section \
> > 2.8 for more information.
> > [1] http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html
> > [2] http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html
> >
> > On Jan 30, 2012, at 10:33 AM, Mohit Anchlia wrote:
> >
> > > HttpClient 4.1.2 - I am using Multithreaded connection manager. Do I
> > > need to explicitly call releaseConnection on this?
> > >
> > > Also, after every http request I am calling
> > > EntityUtils.toByteArray(entity), would it release connection or is
> > > this the right way to release connection?
> > >
> > > I am seeing some wierd behaviour and want to undersand this little more.
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> > >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic