2

As we can see from httpclient-4.5.x quick start, "In order to ensure correct deallocation of system resources the user MUST call CloseableHttpResponse#close() from a finally clause."

But, lets check the code of HttpRequestBase#releaseConnection(). The annotation said "A convenience method to simplify migration from HttpClient 3.1 API. This method is equivalent to {@link #reset()}."

public abstract class HttpRequestBase extends AbstractExecutionAwareRequest
    implements HttpUriRequest, Configurable {
......
/**
     * A convenience method to simplify migration from HttpClient 3.1 API. This method is
     * equivalent to {@link #reset()}.
     *
     * @since 4.2
     */
    public void releaseConnection() {
        reset();
    }

....
}

I want to ask, now that we only need to call CloseableHttpResponse#close() from a finally clause to release resource, then what is HttpRequestBase#releaseConnection() used to? what AbstractExecutionAwareRequest#reset() is used to? When should we use HttpRequestBase#releaseConnection() or AbstractExecutionAwareRequest#reset().

tejas
  • 1,795
  • 1
  • 16
  • 34
cloud
  • 41
  • 3
  • Same problem here. Some people in [here](https://stackoverflow.com/a/12388980/9304616) say it's a method to release connection, but I think it's not that way according to the doc. – Lebecca May 29 '20 at 14:01

1 Answers1

1

I have track the source of HttpRequestBase#releaseConnection() and CloseableHttpResponse#close(), Both the two method will call the HttpClientConnectionManager#releaseConnection(). So i think their all can be used to relase the connection. But now that the official document recommend us to use CloseableHttpResponse#close(), we'd better to us CloseableHttpResponse#close() to release the connection.

cloud
  • 41
  • 3