On Tue, 2016-05-17 at 23:28 +0300, Michael Velbaum wrote:
> Hi,
> 
> I have a few questions regarding proper resource de-allocation, as this
> topic is not covered in detail in the tutorial.
> 
> 1. The CloseableHttpClient interface allows you to close an HttpClient.
> What advantage does manually closing an HttpClient have over simply letting
> the HttpClient object be garbage collected when I'm done with it?
> 

It ensures immediate shutdown and deallocation of system resources
allocated by persistent (kept-alive) connection.

> 2. Do I need to use a CloseableHttpResponse and manually close the response
> if I already use EntityUtils.toByteArray(entity) to fully consume the
> response?
> 

Yes, you do. You should always close responses with try-finally or
try-with-resources to make sure resources allocated by the response get
deallocated even in case of an exception.

If the response content has been fully consumed by the time
CloseableHttpResponse#close is called the overhead of the #close method
will be literally a true/false check on a volatile boolean variable.

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
For additional commands, e-mail: httpclient-users-h...@hc.apache.org

Reply via email to