问题
Httpclient高并发多线程同时请求的时候, Connection pool shut down
先看下httpclient这个对象的创建方式
https://www.jianshu.com/p/14c005e9287c
接着根据上面的了解进行改变对象的创建方式。
下面有一个例子可以查看:
http://www.mamicode.com/info-detail-2297359.html
最后就是我的改写这样的:
public static void createClient() throws Exception {
SSLContext sslcontext = SSLContexts.createDefault();
SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1.2" },
null,SSLConnectionSocketFactory.getDefaultHostnameVerifier());
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", factory) // 用来配置支持的协议
.build();
// 加个共享连接池
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
connectionManager.setMaxTotal(10);
connectionManager.setDefaultMaxPerRoute(10);
httpClient = HttpClientBuilder.create().setConnectionManager(connectionManager).setConnectionManagerShared(true).build();
// httpClient = HttpClientBuilder.create().setSSLSocketFactory(factory).build();
}