hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: PoolingClientconnectionManager release connection
Date Tue, 04 Dec 2012 20:38:42 GMT
On Mon, 2012-12-03 at 15:42 -0800, Jaikit Savla wrote:
> Hi Folks,
> 
> I am using PoolingClientConnectionManager and wanted to make sure I am not leaking connections.
I read Oleg's comment here ( http://www.mail-archive.com/httpclient-users@hc.apache.org/msg06061.html)
> 
> My question is:
> HttpGet httpGet = new HttpGet("http://targethost/stuff";;);
> HttpResponse response = httpclient.execute(httpGet);
> try { HttpEntity entity = response1.getEntity(); // do something useful with the response
body // and manually ensure it is fully consumed
> } finally { EntityUtils.consume(response.getEntity());
> }
> 
> Will these also release connection ? (since documentation for EntityUtils.consume does
not mention that)
> 

Yes, it will.

> question2:
> DefaultHttpClient httpclient = new DefaultHttpClient();
> HttpGet httpGet = new HttpGet("http://targethost/homepage";;);
> HttpResponse response = httpclient.execute(httpGet);
> try { System.out.println(response1.getStatusLine()); HttpEntity entity = response1.getEntity();
// do something useful with the response body
> } finally { httpGet.releaseConnection();
> }
> 
> Will above close the stream too ?
> 

No, it will not. That is, the #close method of the content stream will
not be called. However, all the resources associated with it will be
freed.

Oleg

> Thanks,
> Jaikit
> 
> ---------------------------------------------------------------------
> 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