This baby novice, do not spray! Directly on the code,
Thread-wide sharing issues: sharing the same block of data between each thread, one data corruption is all damaged, you need to run a bit!
public class Threads {
private static Hashmap<thread, integer> data = new hashmap<thread,integer> ();
public static void Main (string[] args) {
for (int i = 0; i < 2; i++) {
New Thread (New Runnable () {
@Override
public void Run () {
int value = new Random (). Nextint (1000);
Data.put (Thread.CurrentThread (), value);
System.out.println ("name is:" +thread.currentthread (). GetName () + "data is:" +value);
A a1 = new A ();
A1.getdata ();
b B1 = new B ();
B1.getdata ();
c C = new C ();
C.getdate ();
}
}). Start ();
}
}
Static Class a{
public void GetData () {
Thread thread = Thread.CurrentThread ();
int value = Data.get (thread);
System.out.println (Thread.getname () + "get data from a" +value);
}
}
Static Class b{
public void GetData () {
Thread thread = Thread.CurrentThread ();
int value = Data.get (thread);
System.out.println (Thread.getname () + "Get data from B" +value);
}
}
Static Class c{
public void GetDate () {
Thread thread = Thread.CurrentThread ();
int value = Data.get (thread);
System.out.println (Thread.getname () + "get data from C" +value);
}
}
}
Java thread-in-the-middle range sharing issues