// int data = threadData.get(Thread.currentThread());
System.out.println("A from " + Thread.currentThread().getName()
+ " get data :" + data);
}
}
static class B{
public void get(){
// int data = threadData.get(Thread.currentThread());
System.out.println("B from " + Thread.currentThread().getName()
+ " get data :" + data);
}
}
}
复制代码
for循环里的两个线程为什么生成的随机数都一样??
在for循环外面新建一个线程,却能生成不同的随机数?谁给解释一下,这个很蹊跷。
---------------运行结果:------------------
Thread-0 has put data :1500315473
Thread-1 has put data :1500315473
Thread-2 has put data :445127673
A from Thread-0 get data :445127673
A from Thread-2 get data :445127673
A from Thread-1 get data :445127673
B from Thread-1 get data :445127673
B from Thread-2 get data :445127673
B from Thread-0 get data :445127673