//结合java线程数据共享1一起看,会更容易理解
//ThreadLocal 这个类就是把当前线程和数据用HashMap的形式一起存起来
public class ThreadLocalTest {
private static ThreadLocal shareData = new ThreadLocal();
public static void main(String[] args) {
for (int i = 0; i < 2; i++) {
new Thread(){
public void run(){
int data = new Random().nextInt();
shareData.set(data);
System.out.println(Thread.currentThread().getName() + data);
System.out.println("moudle A in " + Thread.currentThread().getName() + shareData.get());
System.out.println("moudle B in " + Thread.currentThread().getName() + shareData.get());
}
}.start();
}
}
}