NOTE

Fair Semaphore

AQS shared acquisition with predecessor-aware fairness and the throughput trade-off of ordered permit allocation.

JavaCreated Updated 1 min readhistorical

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

1. Fair Permit Allocation

A fair Java Semaphore generally avoids letting a new blocking acquirer jump ahead of already queued predecessors.

AQS shared mode tracks permits in synchronization state and wakes/propagates eligible waiters as permits become available.

2. Trade-Off

Fairness can improve wait predictability but usually reduces throughput because opportunistic acquisition is constrained.

3. Caveat

Fairness is defined at specific ordering points inside acquisition, not as a hard real-time FIFO guarantee. Scheduling and untimed tryAcquire behavior can still affect observed order.

Use fair mode because fairness is a requirement, not because it is automatically more correct.

Loading helpful count