package threads; import java.util.Random; public class DataRace extends Thread { static int common = 0; public void run() { int local = common; if (new Random().nextInt(1001) > 500) { try { Thread.sleep(new Random().nextInt(2000)); } catch(InterruptedException e) {} } local = local + 1; common = local; } public static void main(String[] args) { int threadNumber = 3; Thread array[] = new Thread[threadNumber]; for (int i = 0; i < 3; i++) (array[i] = new DataRace()).start(); try { for (int i=0; i < 3; i++) array[i].join(); } catch (InterruptedException e) { System.out.println(e.getMessage()); e.printStackTrace(); } System.out.println("Common Value: " + common); // may not be 3 } }