package others;
/**
* InheritableThreadLocal:继承上下文 环境的数据,拷贝一份给子线程 起点
*
* @author
*
*/
public class TestThreadLocal04 {
private static InheritableThreadLocal<Integer> threadLocal = new InheritableThreadLocal<>();
public static void main(String[] args) {
threadLocal.set(2);
System.out.println(Thread.currentThread().getName()+"-->"+threadLocal.get());
//此线程由main线程开辟
new Thread(()->{
System.out.println(Thread.currentThread().getName()+"-->"+threadLocal.get());
threadLocal.set(200);
System.out.println(Thread.currentThread().getName()+"-->"+threadLocal.get());
}).start();
}
}
多线程 ThreadLocal(4)
最新推荐文章于 2024-06-15 20:17:46 发布