class R implements Runnable {
public void run() {
// System.out.println(
// "Running " + Thread.currentThread().getName());
// This statement may do bad things!
data[ix] = ix++;
}
}
data = new int[MAX];
System.out.println("Starting " + MAX + " threads...");
for (int i=0; i<MAX; i++) {
new Thread(new R()).start();
}
System.out.println("Sleeping to let threads finish");
Thread.sleep(4000);
for (int i=0; i<MAX; i++) {
if (i != data[i])
System.out.println("Discrepancy at " + i + ": " + data[i]);
}
System.out.println("Done.");