1. 使用TreadLocal保存每个调用的uuid
ThreadLocalInfo:
import java.util.HashMap;
/**
* @Description:
* @Author: wangkebing
* @Date: 2020/12/23
* @Param:
* @Retrun:
**/
public class ThreadLocalInfo extends HashMap<String, Object> {
public ThreadLocalInfo addUUID(String uuid) {
this.put("uuid", uuid);
return this;
}
public ThreadLocalInfo addTimeStamp(String timeStamp) {
this.put("timeStamp", timeStamp);
return this;
}
public String getUUID() {
return this.get("uuid") == null ? null : (String) this.get("uuid");
}
public String getTimeStamp() {
return this.get("timeStamp") == null ? null : (String) this.get("timeStamp");
}
}
TLInfo:
/**
* @Description:
* @Author: wangkebing
* @Date: 2020/12/23
* @Param:
* @Retrun:
**/
public class TLInfo {
private TLInfo() {
}
private static final ThreadLocal<ThreadLocalInfo> LOCAL = new ThreadLocal<ThreadLocalInfo>();
public static void set(ThreadLocalInfo threadLocalInfo) {
LOCAL.set(threadLocalInfo);
}
public static ThreadLocalInfo get() {
return LOCAL.get();
}
public static void setUUID(String uuid) {
ThreadLocalInfo threadLocalInfo = TLInfo.get() == null ? new ThreadLocalInfo() : TLInfo.get();
TLInfo.set(threadLocalInfo.addUUID(uuid));
}
public static String getUUID() {
return TLInfo.get() == null ? null : TLInfo.get().getUUID();
}
public static void setTimeStamp(String timeStamp) {
ThreadLocalInfo threadLocalInfo = TLInfo.get() == null ? new ThreadLocalInfo() : TLInfo.get();
TLInfo.set(threadLocalInfo.addTimeStamp(timeStamp));
}
public static String getTimeSta