title: Synchronized on a monitor
body: <p>I'm just trying to further my understanding of this concept.</p>
  
  <p>We have a monitor, let's say a queue or a map of some sort. This monitor has methods to put objects on, and get objects off. In order to be thread safe, the monitor will lock on it's put methods and on it's get methods. When a thread is synchronized to this monitor, it's constantly trying to obtain this monitor's right's so it can proceed with what it needs to do. Does this sound right? </p>
  
  <p>Another question, how does the flow of control work here. Which code is executed once the thread has gained access to the monitor? I'm finding it hard to debug multi-threaded programs with just print statements, it get's really messy and confusing.</p>
  
  <pre><code>public void run(){
      try{
          synchronized (monitor){
              while (monitor is empty){
                   monitor.wait(); // Does this line pause the thread or the monitor?
              }
  
              System.out.println("Done Waiting");
          }
          System.out.println("Out of the synchronized block");
      } 
  }
  </code></pre>