问题
I have changed my code version from http to https and I am using HttpClient client = HttpClientFactory.getHttpsClient()
for execution purposes. When I am trying to run my code for the first time it is running fine and next time is throwing the exception
java.lang.IllegalStateException: Connection pool shut down exception
I am using 4.5HC.
回答1:
Do not close your client after a request if you are pooling the connections.
That is, you are probably doing something like this:
PoolingHttpClientConnectionManager pool = new PoolingHttpClientConnectionManager();
...
CloseableHttpClient httpclient = HttpClients.custom()
.setConnectionManager(pool)
.build();
try { // try-with-resources
HttpGet httpget = new HttpGet(url.toURI());
try (CloseableHttpResponse response = httpclient.execute(httpget);
InputStream fis = response.getEntity().getContent();
ReadableByteChannel channel = Channels.newChannel(fis)) {
// ... get data ...
} finally {
httpclient.close(); <====== !!
}
} catch (IOException | URISyntaxException e) {
// exception handling ...
}
That httpclient.close()
is causing your next pooled connection to fail.
来源:https://stackoverflow.com/questions/54513926/java-lang-illegalstateexception-connection-pool-shut-down-exception