IllegalMonitorStateException

Base on JavaDoc, IllegalMonitorStateException is thrown to indicate that a thread has attempted to wait on an object's monitor or to notify other threads waiting on an object's monitor without owning the specified monitor.

This can happens when you perform notify, notifyAll, wait method for an object, especially, when you are trying to perform cross thread notify and wait operation.

The way to solve this issue is to surround the object to be notified or wait with synchornized block


synchronized (obj) {
obj.wait();
}

Comments

Popular Posts