On Fri, 2015-04-24 at 13:22 +0200, Joan Balagueró wrote:
> Hello,
> 
> Regarding this posts:
> 
> > Any help in this issue would be much appreciated. 
> > Thanks
> > mrhuang
> > 
> 
> > I am not quite sure I understand the issue. You should not even be using 
> > #releaseConnection in the first place. It is provided for compatibility 
> > with HC 3.x. You should always close CloseableHttpResponse in a try-finally 
> > or try-with-resources.
> > Oleg
> 
> You say that using CloseableHttpResponse is the right way to release a 
> connection. Currently, our code to release a connection is the above (works 
> fine):
> 
>   if (entity != null)
>   {
>    try { EntityUtils.consume(entity); }
>    catch (Exception e) {}
>   }
>   else
>   {
>    if (objPost != null) objPost.abort();
>    else if (objGet != null) objGet.abort();
>   }
> 
> Do you think it's preferrable to change this code by one that directly closes 
> the CloseableHttpResponse?
> 

It is a matter of taste. I find try-finally or try-with-resources just
nicer

---
HttpGet get = new HttpGet("http://stuff/";);
try (CloseableHttpResponse response = client.execute(get)) {
    System.out.println(response.getStatusLine());
    EntityUtils.consume(entity);
}
---

Oleg

> Thanks,
> 
> Joan.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to