I have a piece of code (simplified):
if(reentrantLockObject.isLocked()) {
reentrantLockObject.unlock();
}
where reentrantLockObject is java.util.concurrent.locks.ReentrantLock. Sometimes I get IllegalMonitorStateException. It seams that lock was released between check and unlock() call. How can I prevent this exception?