InterviewSolution
| 1. |
When Invalidmonitorstateexception Is Thrown? Why? |
|
Answer» 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 synchronized block/method of that object and STILL trying to call wait()/notify()/notifyAll()) wait(), notify() and notifyAll() all throw IllegalMonitorStateException. since This exception is a subclass of RuntimeException so we 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 wait(), notify(), notifyAll() methods. 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 synchronized block/method of that object and still trying to call wait()/notify()/notifyAll()) wait(), notify() and notifyAll() all throw IllegalMonitorStateException. since This exception is a subclass of RuntimeException so we 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 wait(), notify(), notifyAll() methods. |
|