java.lang.IllegalStateException: Connection pool shut down exception

假如想象 提交于 2020-01-25 08:01:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!