InterviewSolution
| 1. |
What Is Reentrantlock In Java? |
|
Answer» ReentrantLock is a CONCRETE IMPLEMENTATION of the Lock interface which is PRESENT injava.util.concurrent.locks package. Every object created in Java has one mutually exclusive lock associated with it. When you are using synchronized you are using that lock implicitly (with no other feature) whereas when you are using any of the lock implementation (like Reentrant lock) you are using that lock explicitly. Which means there are methods like lock() to acquire the lock and unlock() to release the lock. Along with that ReentrantLock provides MANY other features like fairness, ability to interrupt and a thread waiting for a lock only for a specified PERIOD. ReentrantLock is a concrete implementation of the Lock interface which is present injava.util.concurrent.locks package. Every object created in Java has one mutually exclusive lock associated with it. When you are using synchronized you are using that lock implicitly (with no other feature) whereas when you are using any of the lock implementation (like Reentrant lock) you are using that lock explicitly. Which means there are methods like lock() to acquire the lock and unlock() to release the lock. Along with that ReentrantLock provides many other features like fairness, ability to interrupt and a thread waiting for a lock only for a specified period. |
|