// Filename SafeReader.java // // Written for JFL book Chapter 8 see text. // Fintan Culwin, v0.1, January 1997 // modified by X. Meng to include synchronized reader // mar-25-1998 import Synch; public class SafeReader extends Thread { Synch readThis; public SafeReader( Synch toRead ) { readThis = toRead; } // End RoomFiller Constructor; public void run() { int firstAttribute; int secondAttribute; while ( true ) { synchronized (readThis) { firstAttribute = readThis.getAnAttribute(); secondAttribute = readThis.getAnotherAttribute(); } if ( firstAttribute != secondAttribute) { System.out.println( "Danger proved ... " + firstAttribute + " and " + secondAttribute + "."); } // End if } // End while. } // End run. } // End SafeReader.