ThreadLocal在线程内部实现数据的共享
//编写ThreadLocalAPI
public class ThreadLocalUtil {
private static ThreadLocal thread = new ThreadLocal<>();
public static void set(User user) {
thread.set(user);
}
public static User get() {
return thread.get();
}
//防止内存泄漏问题
public static void remove() {
thread.remove();
}
}