Java Coding Assignment- Multi-Threading

profileKnockKnockDragon
badsyncSteamBoiler.java

package part2; //class to simulate a steam boiler to illustrate a race condition //in unsynchronized threads public class badsyncSteamBoiler { static int pressureGauge = 0; static final int safetyLimit = 50; public static void main(String [] args) { badsyncPressure []psi = new badsyncPressure[10]; for (int i = 0; i < 10; i++) { psi[i] = new badsyncPressure(); 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!"); } }