Treadlocal类有个内置map
Treadlocal类类一旦调用set(Object)方法,以当前线程为key,存入map中,
Treadlocal类类一旦调用get()方法,以当前线程为key,拿出value;
public class Demo {
static ThreadLocal t1 = new ThreadLocal();
public static void main(String[] args) {
t1.set("小异");
new MyThread(t1).start();
}
}
class MyThread extends Thread{
private ThreadLocal t1;
public MyThread(ThreadLocal t1) {
this.t1 = t1;
}
@Override
public void run() {
System.out.println("===== :" +t1.get());//什么都没有!!!!!!!
}