ThreadLocal是什么? This class provides thread-local variables. These variables differ from their normal counterparts in that each thread that accesses one (via its get or set method) has its own, indepen
ThreadLocal 提供线程局部变量,使用它保存的变量在每个线程中都是独立的变量副本,ThreadLocal 通常是类中的私有静态字段,用于将状态与线程相关联。如下所示: public static final ThreadLocal threadLocal1 = new ThreadLocal(); public static final ThreadLocal threadLocal2 =
概念 threadlocal为每一个线程提供一个单独的存储空间,具有线程隔离的作用,只有在线程内才能获取到对应的值,线程外则不能访问 工具类 public class BaseContext { public static ThreadLocal threadLocal = new ThreadLocal(); public static void setCurrentId(Long id) {