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);
}
}
}
|