What are Reentrant Locks?


anirudh bhatnagar

In Java 5.0 a new addition was made to enhance the intrinsic locking capabilities, called as Reentrant Lock.
Prior to this, ‘synchronized’ and ‘volatile’ were the means for achieving concurrency.

Synchronized uses intrinsic locks or monitors. Every object in Java has an intrinsic lock associated with it. Whenever a thread tries to access a synchronized block or method it acquires the intrinsic lock or the monitor on that object. In case of static methods, the thread acquires the lock over the class object.
Intrinsic locking mechanism is a clean approach in terms of writing code and is pretty good for most of the use-cases. So why do we need additional feature of Explicit Locks? Lets discuss.

View original post 744 more words