title: Java - use wait() method until specific time reached
body: <p>I have a thread that runs in the background of my program and detects when a deadline (set by user input at the beginning of the program) occurs. I have implemented this in a <code>while</code> loop and using the <code>sleep(1000)</code> method.</p>
  
  <p>It all works ok, but I would like to change it over from using <code>sleep(1000)</code> to using <code>wait()</code> and <code>notifyAll()</code> to be consistent with the rest of my code, and to make the alert happen in real-time rather than lagging by a part of a second until the thread re-awakens.</p>
  
  <p>Here is what I currently have</p>
  
  <pre><code>    //Retrieve current date and time...
      Calendar now = Calendar.getInstance();
  
      //deadline not yet reached
      while(now.before(deadline))
      {
          try
          {
              //wait a second and try again
              sleep(1000);
          }
          catch (InterruptedException intEx)
          {
              //Do nothing.
          }
  
          //Update current date and time...
          now = Calendar.getInstance();
          //run loop again
      }
  
      ////////////////////////////
      ///alert user of deadline///
      ////////////////////////////
  </code></pre>
  
  <p>I have tried to change it over to use <code>wait()</code>, but had no success. Can anybody see a way of changing the existing code over to implement the methods I mentioned?</p>
  
  <p>Thanks in advance,
  Mark</p>