Below is the all the information before the thread is locked and after the thread is unlocked. I m using the method lock() and unlock() the ReentrantLock. However, although some process has unlocked the lock, another process could not lock the same lock.
-
Provide the source please, its hard to tell from a log-output only – gustf Apr 04 '16 at 13:11
1 Answers
Puts on his diviner hat
Your logs contain references to two different locks -
java.util.concurrent.locks.ReentrantLock@1624f737
and java.util.concurrent.locks.ReentrantLock@17b002cd
. Your question doesn't make it very clear what exactly are you doing and whether having two locks is intentional, but let's assume that it is.
Whenever you are logging that you have freed some of the two locks, the string representation of the lock still contains [Locked by thread Thread-X]
. If you are logging from the same thread, exactly after trying to unlock the lock, you should expect to see an [Unlocked]
suffix (see the Javadoc of ReentrantLock.toString()
)
It looks like you got some small but very important piece of code wrong.
Most probably, you have called ReentrantLock.lock()
multiple times from the current owner of the lock and you are trying to release the lock by calling ReentrantLock.unlock()
a single time (or more generally, less than the number of times you've called lock()
).
There are also other possible explanations - e.g. if you are swallowing all thrown exceptions, you may be trying to unlock from the wrong thread without noticing (an IllegalMonitorStateException
should be thrown in that case; I've just spent a fun 10 minutes coding up an example to see how this can be done). Still, these explanations are much less probable than the one above.

- 16,032
- 5
- 53
- 55