Java Coding Assignment- Multi-Threading
package part2; //thread class to raise the pressure in the Boiler class syncPressure extends Thread { static Object O = new Object(); void RaisePressure() { synchronized(O) { if (syncSteamBoiler.pressureGauge < syncSteamBoiler.safetyLimit-15) { //wait briefly to simulate some calculations try {sleep(500); } catch (Exception e) { } syncSteamBoiler.pressureGauge+= 15; //raise the pressure 15 psi System.out.println("Thread " + this.getName() + " finds pressure within limits - increases pressure"); } else System.out.println("Thread" + this.getName() + " finds pressure too high - do nothing"); }//end synchronized object } public void run() { RaisePressure(); //this thread is to raise the pressure } }