InheritableThreadLocal的测试

package t1;

public class TestThread8 {
private static volatile InheritableThreadLocal<String> intVal = new InheritableThreadLocal<String>();

public static void main(String[] args) {
Runnable rP = () -> {
intVal.set(new String("10"));
Runnable rC = () -> {
Thread thd = Thread.currentThread();
String name = thd.getName();
System.out.printf("%s %s", name, intVal.get());
};
Thread thdChild = new Thread(rC);
thdChild.setName("child");
thdChild.start();
};
new Thread(rP).start();
}
}

输出结果:

 

posted @ 2020-03-31 09:27  工设091  阅读(120)  评论(0)    收藏  举报