// class to simulate a steam boiler to illustrate a race condition
//in unsynchronized threads
public class SteamBoiler1 {
   static int pressureGauge = 0;
	static final int safetyLimit = 50;
	
	public static void main(String [] args) {
	  pressure1 []psi = new pressure1[10];
	  for (int i = 0; i < 10; i++) {
	     psi[i] = new pressure1();
	     psi[i].start();
	  }
	  //we now have 10 threads in execution to monitor the pressure
	  try {
	     for (int i = 0; i < 10; i++)
		     psi[i].join();  //wait for the thread to finish
	         //psi[i].sleep(200); 
		}
		catch (Exception e) { } //do nothing
		System.out.println();
		System.out.print("Gauge reads " + pressureGauge + ", the safe limit is " + safetyLimit);
		if (pressureGauge > safetyLimit)
			System.out.println("...B O O M ! ! !");
		else System.out.println("...System OK!");
	}
}
