First Case: If you wait or monitor on an object, without taking lock on that object means without synchronizing on that object, then IllegalMonitorStateException is thrown.
Second Case: If you take lock on an object, here synchronized(str), but you change the object here str="String object changed here.."; and call wait() on that object here str.wait(); here str object has been changed. It is different Object than you have taken lock on. Now you donot have lock on new str object. so here if str.wait() called it will throw IllegalMonitorStateException, means your are monitoring on such an object that is not locked by you.
Joined: Oct 24, 2008
thnak you for you'r explanation...............
but i have problem.In the following code i used wait method without using synchronization .but it compiles and run fine gives CDA as out put.but it not prints B in out put. can You explain this