ReentrantLock
ReentrantLock is an explicit mutual exclusion lock in Java's java.util.concurrent.locks package. It implements the Lock interface and offers features beyond the built-in synchronized keyword, including reentrancy, fairness control, and associated Condition objects for complex wait/notify patterns. A ReentrantLock can be held by at most one thread at a time, and it exposes methods for locking, unlocking, and querying the lock state.
The lock is reentrant: if a thread currently holds the lock, it may acquire it again without
Fairness can be configured at construction time. ReentrantLock(boolean fair) creates either a fair lock, which favors
Core usage patterns include lock(), which acquires the lock, and unlock(), which releases it. Unlock must be
Condition objects created via newCondition() are associated with the lock and enable advanced wait/notify semantics through
In practice, ReentrantLock offers flexible locking and often better scalability than intrinsic synchronization, while requiring disciplined