Priyanka S
Priyanka S

Reputation: 1

java.lang.IllegalStateException: Connection pool shut down exception

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.

Upvotes: 0

Views: 3188

Answers (1)

Campa
Campa

Reputation: 4505

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.

Upvotes: 1

Related Questions