CountDownLatch vs CyclicBarrier vs Semaphore — which coordination tool when?
Reviewed by Gurusankar M.
Short Answer
CountDownLatch: one-shot 'wait for N events' (can't reset). CyclicBarrier: N threads wait for each other, reusable each round. Semaphore: limits concurrent access to N permits (rate/resource limiting).
On this page
Concept Made Simple
Coffee Chat Question
“CountDownLatch vs CyclicBarrier vs Semaphore — which coordination tool when?”
Remember It Faster
Mind Map Answer
- CountDownLatch
- wait for N to finish, one-shot
- CyclicBarrier
- N threads rendezvous, reusable
- Semaphore
- N permits — throttle concurrency
Learn by Doing
Hands-on Keyboard
Semaphore permits = new Semaphore(10); // max 10 concurrent calls
permits.acquire();
try { callRateLimitedApi(); }
finally { permits.release(); }Think Beyond the Expected
What If?
You need to throttle calls to a downstream API to 10 concurrent — which tool?
A Semaphore with 10 permits: each thread acquire()s before calling and release()s after (in finally). It bounds in-flight requests to protect the dependency — a simple bulkhead / concurrency limiter.
Real World
CountDownLatch coordinates 'wait until all warm-up tasks complete'; Semaphore implements bulkheads/rate limits to protect fragile downstreams; CyclicBarrier is common in phased simulations/tests.
Interviewer's Expectation
Keywords they're listening for:
- one-shot vs reusable
- latch waits for events
- barrier = mutual rendezvous
- semaphore = permits/throttle
Common Mistakes
- Using a latch where you need reuse (need barrier)
- Forgetting to release() a semaphore permit
- Confusing barrier (mutual) with latch (one-way)
Best Practices
- release() permits in finally
- Pick the tool by reuse + direction of waiting
- Prefer library limiters (Resilience4j) for production throttling
Follow-up Questions
- Why can't a CountDownLatch be reused?
- How would you build a bulkhead with a Semaphore?
- What does CyclicBarrier's barrier action do?
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: Locks (Multithreading) Interview question: "CountDownLatch vs CyclicBarrier vs Semaphore — which coordination tool when?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
Affiliate links
Tools for Your Developer Workspace
Equipment for a comfortable, productive setup.
As an Amazon Associate I earn from qualifying purchases.
- MonitorView on Amazon : BenQ EW2790U 27-inch Monitor (opens in a new tab)
BenQ EW2790U 27-inch Monitor
- LaptopView on Amazon : Acer Aspire One Laptop (opens in a new tab)
Acer Aspire One Laptop
- Office ChairView on Amazon : Wakefit Gravita Ergonomic Office Chair (opens in a new tab)
Wakefit Gravita Ergonomic Office Chair