我可以为http和https建立一个公共连接池吗? 如果是,我该如何配置呢?
这是我的连接池管理器
public class PoolConnectionManager {
private static PoolConnectionManager instance;
private static CredentialsProvider credsProvider = new BasicCredentialsProvider();
private PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = null;
public static RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(5000).setConnectionRequestTimeout(10000)
.setConnectTimeout(5000).build();
public static synchronized PoolConnectionManager getInstance() {
if (instance == null) {
synchronized (PoolConnectionManager.class) {
if (instance == null) {
instance = new PoolConnectionManager();
}
}
}
return instance;
}
private PoolConnectionManager() {
poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager();
poolingHttpClientConnectionManager.setMaxTotal(50);
poolingHttpClientConnectionManager.setDefaultMaxPerRoute(20);
}
public CloseableHttpClient getHttpClient() {
return HttpClients.custom()
.setConnectionManager(this.poolingHttpClientConnectionManager)
.setDefaultCredentialsProvider(credsProvider)
.setDefaultRequestConfig(requestConfig).build();
}
public PoolingHttpClientConnectionManager getPoolingHttpClientConnectionManager() {
return poolingHttpClientConnectionManager;
}
}
我是否应该使用另一个名为getHttpsClient()的方法并设置证书和信任存储等?