Skip to main content

Can java.util.concurrent.lock.Lock detect deadlocks caused by two threads acquiring the same locks in a different order

Posted by staufferjames on July 15, 2013 at 1:01 PM PDT

Could java.util.concurrent.lock.Lock use a static list of all threads that have locks and ThreadLocal locks lists to know about all in use locks and then check for incorrect order when lock() is called.

Consider:
In lock:
Check the ThreadLocal list and if there are no other locks then proceed.
Else if there are other locks then look through other threads to determine if any have any of the same locks in a different order.
Add current lock to ThreadLocal list.

In unlock:
Remove current lock from ThreadLocal list.

Related Topics >>