All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.schedulerx.worker.util.HttpClientUtil Maven / Gradle / Ivy

There is a newer version: 1.12.2
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy