Proper usage of Apache HttpClient and when to close it. : <p>I am using HttpClient within a servlet to make calls to a resource which I return as the servlets response after some manipulation. </p>

<p>My HttpClient uses PoolingHttpClientConnectionManager. </p>

<p>I create the client like so:</p>

<pre><code>private CloseableHttpClient getConfiguredHttpClient(){
    return HttpClientBuilder
        .create()
        .setDefaultRequestConfig(config)
        .setConnectionReuseStrategy(NoConnectionReuseStrategy.INSTANCE)
        .setConnectionManagerShared(true)
        .setConnectionManager(connManager)
        .build();
}
</code></pre>

<p>I use this client within a Try With Resource within the servlets service method, so it is auto closed. To stop the the connection manager from being closed, I set <code>setConnectionManagerShared</code> to true.</p>

<p>I have seen other code samples that do not close the HttpClient. Should I not be closing this resource?</p>

<p>Thanks</p>
