java子线程中获取父线程的threadLocal中的值
【今日推荐】:为什么一到面试就懵逼!>>> 一、java子线程中获取父线程的threadLocal中的值 threadLocal可以做线程级的数据隔离,那如何在子线程中获取父线程的值呢? 可以使用InheritableThreadLocal /** * Java子线程获取父线程的threadLocal中的值 */ public class ThreadDemo1 { public static final InheritableThreadLocal<String> inheritableThreadLocal = new InheritableThreadLocal<>(); public static final ThreadLocal<String> threadLocal = new ThreadLocal<>(); public static void main(String[] args) throws Exception { inheritableThreadLocal.set("inheritableThreadLocal hello"); threadLocal.set("threadLocal world"); new Thread(()->{ System.out.println(String.format("子线程可继承值:%s",