多线程InheritableThreadLocal

多线程InheritableThreadLocal用法

public class ThreadEnd extends InheritableThreadLocal {

    @Override
    protected Object childValue(Object parentValue) {
        return parentValue;
    }
}
public class Tools {
  public static ThreadEnd t2= new ThreadEnd();
}
   public static void main(String[] args) {

        for(int i=0;i<5;i++){
            Tools.t2.set(i);
        }

        Thread C = new Thread( new ThreadC());
        C.start();
    }

InheritableThreadLocal 用于子线程获取主线程的变量

你可能感兴趣的:(多线程,多线程,java)