title: using Object as a mutex in java
body: <p>Hello there good poeple, I need some help.</p>
  
  <p>I'm writing a music player which streams music from the web. If I pres the play button before the music is done buffering I want it to wait.</p>
  
  <p>I tried doing something like this:</p>
  
  <pre><code>Object mutex = new Object();
  
  public void main() {
      startStreaming();
      mutex.notify();
  }
  
  private void onClickPlayButton() {
      mutex.wait();
  }
  </code></pre>
  
  <p>The problem is that is the playButton is not pressed the <code>mutex.notify()</code> if throws a "<code>llegalMonitorStateException</code>". How do you normally solve problems like this?</p>
  
  <p><strong>EDIT</strong> To make clear. My question is: How do I make the button wait for the "startStreamning" method to finish?</p>