Synchronizers in `java.util.concurrent`
Use Java synchronizers such as latches, barriers, semaphores, phasers, and exchangers when threads must coordinate phases or resource access explicitly.
Synchronizers in java.util.concurrent solve coordination problems that plain locks do not express well. They describe events such as “wait until all parties arrive,” “limit concurrent access to this resource,” or “exchange data at a rendezvous point.”
These tools are powerful because they model coordination intent directly. They are risky when used as puzzle pieces without a clear phase model or ownership story.
The child pages explain the main synchronizers and the kind of concurrency problem each one is actually meant to solve.
In this section
- CountDownLatch in Java
Use `CountDownLatch` in Java when one thread must wait for a fixed number of one-time events or worker completions.
- CyclicBarrier in Java
Use `CyclicBarrier` in Java when a fixed group of worker threads must repeatedly meet at the same phase boundary.
- Semaphore in Java
Use `Semaphore` in Java to bound concurrent access to scarce resources and make admission control explicit.
- Exchanger in Java
Use `Exchanger` in Java when two threads need a rendezvous point to swap data without broader shared-state coordination.
- Phaser in Java
Use `Phaser` in Java when participants can register dynamically across multiple synchronization phases instead of staying fixed.