Apart from the monitor-based synchronisation, Java provides various locks in java.util.concurrent.locks for more flexible and fine-grained locking schemes.
Much like the monitor-based synchronisation, there’s 3 components:
- Locking implementations
- Lock Interface (Acquiring the lock)
- Condition Interface (Signalling Methods)
Architecture
All StdLib lock implementations are built on AbstractQueuedSynchronizer (AQS), which provides the core synchronisation infrastructure:
Sync Queue (Entry Queue):
- Holds threads waiting to acquire the lock
- Analogous to Entry Set in java-monitor
- Doubly-linked list managed by AQS
- FIFO ordered, but fairness setting determines if new threads can “barge” ahead
Condition Queues:
- Holds threads waiting on specific conditions via
await() - Analogous to Wait Set in java-monitor
- Multiple singly-linked lists, one per
Conditionobject - When signalled, threads move from condition queue → sync queue