title: put the current thread to sleep while waiting for another thread
body: <p>At some point in my application, I want to put my main thread (ie., the currently executing thread) to sleep for some time or until the background has finished (and wakes it up), whichever comes first.</p>
  
  <p>Here is what I did (which I thought would work, but didn't)</p>
  
  <pre><code>public static void main(String args[])
  {
      // .... other stuff ...
  
      // show a splash screen
      // just think of this as an image
      showPlashScreen(): 
      new Thread(new Runnable()
      {
            public void run()
            {
                  // do some work here
  
                  // notify everyone after the work is done
                  Thread.currentThread().notifyAll();
            }
      }).start();
  
      // now make the current thread to wait for the background
      // or for at most 1000
      Thread.currentThread().wait(1000);
      disposeSplashScreen();
  
      // ... other stuff ....
  }
  </code></pre>
  
  <p>Executing this, I keep getting <code>java.lang.IllegalMonitorStateException</code></p>
  
  <p>(Partial) stacktrace:</p>
  
  <pre><code>Caused by: java.lang.IllegalMonitorStateException
      at java.lang.Object.wait(Native Method)
  
  .... &lt;cut&gt; ....
  
  Exception in thread "Thread-7" java.lang.IllegalMonitorStateException
      at java.lang.Object.notifyAll(Native Method)
  </code></pre>