title: How does wait() get the Lock back in Java
body: <p>It is an advocated paradigm that wait() should be invoked inside a while loop inside a synchronized block.</p>
  
  <p>My question is how does the waiting() thread get the lock back ?</p>
  
  <pre><code>// Thread 1
      synchronized (mon) {
       while (!condition) 
            mon.wait();
  
      // Do something
      }
  
  //Thread 2
      synchronized (mon) {//set condition appropriately
              mon.notify();
      }
  </code></pre>
  
  <p>Consider the thread 1 runs first and starts waiting for the condition. It releases the lock and the thread 2 obtains the lock sets the condition and notifies thread 1. Now thread 1 gets the lock, checks the condition and starts executing "do something".</p>
  
  <p>My question is when Thread 1 is notified it starts execution from the while condition, the line of code which had Synchronized(mon) is never executed again then how does thread 1 acquire the lock ? What are the internal dynamics that give the lock back to Thread 1 ?</p>