NOTE

Fair ReentrantLock

How fair ReentrantLock reduces barging by honoring queued predecessors, and the throughput/latency trade-off of fairness.

JavaCreated Updated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

1. Fair Acquisition

A fair ReentrantLock(true) generally checks whether earlier queued threads exist before a new contender acquires the free lock.

This reduces barging and gives waiting order more influence.

2. Trade-Off

Fairness often lowers peak throughput because newly running threads cannot opportunistically reacquire a lock even when doing so would avoid a context switch.

Use fairness when starvation/latency distribution matters more than raw throughput.

3. Caveat

Fair does not mean perfectly deterministic FIFO scheduling. OS scheduling, cancellation, timed attempts, and API details affect observed order.

Also, untimed tryLock() has behavior that does not necessarily honor the fairness setting in the same way as normal blocking acquisition.

4. AQS Relationship

Fair locking is a policy layered on AQS-style queue/state machinery. The durable idea is predecessor-aware acquisition, not one old JDK source listing.

Loading helpful count