线程唯一工具类
package com.evatmaster.biz.center.order.utils;
import lombok.Data;
/**
* 线程唯一id工具类
*
* @author
* @since 2023-04-07 16:58
*/
@Data
public class ThreadUniqIdUtil {
private static ThreadLocal<Long> threadLocal = new ThreadLocal<>();
/**
* 获取线程唯一id
*
* @return 结果
*/
public static Long getUniqId() {
return threadLocal.get();
}
/**
* 清楚本地缓存
*/
public static void clear() {
threadLocal.remove();
}
/**
* 每次调用set必须有finally调用clear
*/
public static void set(Long uniqId) {
threadLocal.set(uniqId);
}
}