Balraj Momi wrote:Actually both wait() and notify() method should be called from a synchronized block and by this Is owns a lock on same object
I don't know what you mean by this but if you see, the call to wait in doMore is indeed in a synchronized context. The method doMore is synchronized. So it will have a lock on the this reference and the call to wait is just like calling this.wait(). you don't need to have a lock on the thread object. You are calling wait on the object on which the doMore method was called.
Sunny Narula wrote:Can anyone humor me and post the code it would take to actually print the last "Printed".
For that you need to notify on the object which is passed to the Thread constructor. Like this
But this code will only work if doMore is called before the main method enters the synchronized block. The sleeps will handle it nicely...