java.util.concurrent.locks · java.base · since Java 1.5
ReentrantLock
public class ReentrantLock implements Lock, SerializableExplicit mutual-exclusion lock with the powers synchronized lacks: tryLock, timed and interruptible acquisition, fairness, and multiple Conditions.
Key methods
void lock() / void unlock() | unlock() in finally, always. |
boolean tryLock() / tryLock(long, TimeUnit) | Deadlock-avoiding acquisition. |
void lockInterruptibly() | Cancellable waiting. |
Condition newCondition() | await/signal wait-sets, multiple per lock. |