java.lang.IllegalStateException:连接池关闭异常 [英] java.lang.IllegalStateException: Connection pool shut down exception
问题描述
我已将代码版本从http更改为https,并且我将 HttpClient client = HttpClientFactory.getHttpsClient()
用于执行目的。当我第一次尝试运行我的代码时,它运行良好并且下一次抛出异常
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 :连接池关闭异常
java.lang.IllegalStateException: Connection pool shut down exception
我正在使用4.5HC。
I am using 4.5HC.
推荐答案
如果正在池化连接,请不要在请求后关闭客户端。
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 ...
}
httpclient.close()
导致您的下一个池连接失败。
That httpclient.close()
is causing your next pooled connection to fail.
这篇关于java.lang.IllegalStateException:连接池关闭异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!