According to Sun, it will print 3 4 1 and will never terminate because "notify is issued before wait"
I can understand that the output is
But how on Earth does it print 1?
Is this because two threads are performing the same job, i.e. Waiting (which IS-A Runnable). So the two threads share the same copy of flag? Much like two people are editing the same Word document online.
Also, I don't understand how notify() is issued before wait(). Where can notify be placed so that the waiting thread will receive notification that lock is now free? I'm guessing notify should be out of the synchronized block because you can only have one thread at a time...