com.alibaba.schedulerx.worker.util.HttpClientUtil Maven / Gradle / Ivy
package com.alibaba.schedulerx.worker.util;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
/**
* @Auther: tangtao
* @Date: 2022/12/6 15:13
* @Description:
*/
public class HttpClientUtil {
/**
* closeableHttpClient 同步调用的httpclient
*/
private static CloseableHttpClient closeableHttpClient = null;
public static CloseableHttpClient getCloseableHttpClient() {
if (closeableHttpClient == null) {
synchronized (CloseableHttpClient.class) {
if (closeableHttpClient == null) {
closeableHttpClient = HttpClients.createDefault();
}
}
}
return closeableHttpClient;
}
public static CloseableHttpClient getCloseableHttpClient(Integer maxTotalConnections) {
if (closeableHttpClient == null) {
synchronized (CloseableHttpClient.class) {
if (closeableHttpClient == null) {
if (maxTotalConnections != null){
closeableHttpClient = HttpClients.custom().setMaxConnTotal(maxTotalConnections).build();
}else {
closeableHttpClient = HttpClients.createDefault();
}
}
}
}
return closeableHttpClient;
}
}