Forums Register Login

invalidMonitorState

+Pie Number of slices to send: Send

Can some one give a simple example when InvalidMonitorStateException is thrown? I got these exceptions long time back, but cant recall and didnt understand at that time why exactly i got these.
+Pie Number of slices to send: Send
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.

regards
Deekasha
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
I am not sure that notify and notifyAll throws any exception
+Pie Number of slices to send: Send
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
What's that smell? I think this tiny ad may have stepped in something.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1592 times.
Similar Threads
Abstract inner class
lost assignment?
Rueben or Clay??
Accessing the Servlet Init parameters in jsp
taglib in Web.xml - Just for backward compatibility?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 09:14:19.