different states in synchronization
<p>i have two threads thread1 and thread2</p>

<p><strong>within thread1</strong></p>

<pre><code>synchronized(lock) {  
    lock.wait();  
    if(lock == null)
        {execute1}  
    if(lock != null)  
        {execute2}   
}  
</code></pre>

<p><strong>within thread2</strong></p>

<pre><code>synchronized(lock) {  
    lock.notify();  
    lock = null;  
}  
</code></pre>

<p>thread1 is called first followed by thread2.<br>
after thread1 calls wait it releases its lock. And thread2 calls notify and sets lock to null.<br>
Now when thread1 tries to acquire lock again why is it not throwing any exception. since lock is set to null and thread1 tries to acquire that lock, shouldn't it throw a null pointer exception when trying acquire the lock.<br>
if it not throwing any exception then thread1 is still reading lock value not null. so shouldn't it execute statements {execute2}? </p>
