
 caller must be synchronized on <code>monitor</code>.

 <p>Here's a sample class that uses <code>waitUntilNotified()</code> to await a specific state. Note
 that the call is made within a loop to avoid unnecessary waiting and to mitigate spurious
 notifications. <pre><code>

   class Dice {
     Random random = new Random();
     int latestTotal;

     public synchronized void roll() {
       latestTotal = 2 + random.nextInt(6) + random.nextInt(6);
       System.out.println("Rolled " + latestTotal);
      