-
@return
*/
private static Semaphore getSemaphoreInstance() {
//只能1个线程同时访问
synchronized (OkHttpUtils.class) {
if (semaphore == null) {
semaphore = new Semaphore(0);
}
}
return semaphore;
}
/**
-
创建OkHttpUtils
-
@return
*/
public static OkHttpUtils builder() {
return new OkHttpUtils();
}
/**
-
添加url
-
@param url
-
@return
*/
public OkHttpUtils url(String url) {
this.url = url;
return this;
}
/**
-
添加参数
-
@param key 参数名
-
@param value 参数值
-
@return
*/
public OkHttpUtils addParam(String key, String value) {
if (paramMap == null) {
paramMap = new LinkedHashMap<>(16);
}
paramMap.put(key, value);
return this;
}
/**
-
添加请求头
-
@param key 参数名
-
@param value 参数值
-
@return
*/
public OkHttpUtils addHeader(String key, String value) {
if (headerMap == null) {
headerMap = new LinkedHashMap<>(16);
}
headerMap.put(key, value);
return this;