作者: Rain2692 时间: 2014-12-6 17:24
能贴代码不,完全看不清。。作者: EYE_SEE_YOU 时间: 2014-12-6 17:30
package game;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
public class Test7 {
static Map<String,Integer> map = new HashMap<String,Integer>();
public static void main(String[] args) {
for(int x=0;x<5;x++)
{
new Thread(new Runnable()
{
public void run()
{
int data = new Random().nextInt();
System.out.println(Thread.currentThread().getName()+" put "+data);
map.put(Thread.currentThread().getName(), data);
A.get();
B.get();
}
}).start();
}
}
static class A
{
public static void get()
{
int data = map.get(Thread.currentThread().getName());
System.out.println("A from "+Thread.currentThread().getName()+" get "+data);
}
}
static class B
{
public static void get()
{
int data = map.get(Thread.currentThread().getName());
System.out.println("B from "+Thread.currentThread().getName()+" get "+data);
}
}