TickTock2.java


// No calls to wait() or notify().
public class TickTock2 {

  String state; // contains the state of the clock

  synchronized void tick(boolean running) {
    if(!running) { // stop the clock
      state = "ticked";
      return;
    }

    System.out.print("Tick ");

    state = "ticked"; // set the current state to ticked
  }

  synchronized void tock(boolean running) {
    if(!running) { // stop the clock
      state = "tocked";
      return;
    }

    System.out.println("Tock");

    state = "tocked"; // set the current state to tocked
  }
}


Results




Maintained by John Loomis, updated Mon Nov 19 21:46:44 2012