hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mohit Anchlia <mohitanch...@gmail.com>
Subject Re: Releasing Connection
Date Tue, 31 Jan 2012 17:07:43 GMT
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


Mime
View raw message