java.lang.IllegalStateException:连接池关闭异常
我已将代码版本从http更改为https,并使用java.lang.IllegalStateException:连接池关闭异常,java,httpurlconnection,connection-pooling,Java,Httpurlconnection,Connection Pooling,我已将代码版本从http更改为https,并使用HttpClient client=HttpClientFactory.getHttpsClient()执行。当我第一次尝试运行我的代码时,它运行良好,下一次抛出异常 java.lang.IllegalStateException:连接池关闭异常 我使用的是4.5HC。如果要共享连接,请不要在请求后关闭客户端 也就是说,您可能正在做这样的事情: PoolingHttpClientConnectionManager pool = new Poolin
HttpClient client=HttpClientFactory.getHttpsClient()
执行。当我第一次尝试运行我的代码时,它运行良好,下一次抛出异常
java.lang.IllegalStateException:连接池关闭异常
我使用的是4.5HC。如果要共享连接,请不要在请求后关闭客户端 也就是说,您可能正在做这样的事情:
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 ...
}
poolghttpclientconnectionmanager pool=new-poolghttpclientconnectionmanager();
...
CloseableHttpClient httpclient=HttpClients.custom()
.setConnectionManager(池)
.build();
try{//try with resources
HttpGet-HttpGet=newhttpget(url.toURI());
try(CloseableHttpResponse-response=httpclient.execute(httpget);
InputStream fis=response.getEntity().getContent();
ReadableByteChannel通道=通道。新通道(fis)){
//…获取数据。。。
}最后{
httpclient.close();请在此处发布导致问题的代码。