Hi Mohit , this exception is thrown when you try to call wait/notify/notifyAll any of these methods for an Object from a point in your program where u are not having a lock on that object.(i.e. u r not executing any synch. block/method of that object and still trying to call wait/notify/notifyAll) here is a code first run it as it is. and the uncomment the lines which are bold. again run it and u will get an exception.
Joined: Sep 23, 2000
thanks deekasha, that was great example. Another doubt which got clarified in the process, is that the compiler doesnt ensures that the wait() notify() methods are called from within a synchronized block.
I am not sure that notify and notifyAll throws any exception
Joined: May 06, 2000
Hi Vladimir, notify and notifyAll both throw IllegalMonitorStateException. since This exception is a subclass of Runtime exception so u r not bound to catch it (although u may if u want to). and being a runtimeexception this exception is not mentioned in the signature of notify,notifyAll methods. regards Deekasha