CountDownLatch vs CyclicBarrier vs Semaphore — which coordination tool when?
⚡ 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).
☕Coffee Chat Question
Concept Made Simple
“CountDownLatch vs CyclicBarrier vs Semaphore — which coordination tool when?”
🧠Mind Map Answer
Remember It Faster
⌨️Hands-on Keyboard
Learn by Doing
Semaphore permits = new Semaphore(10); // max 10 concurrent calls
permits.acquire();
try { callRateLimitedApi(); }
finally { permits.release(); }🔥What If?
Think Beyond the Expected
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:
⚠️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
- 1Why can't a CountDownLatch be reused?
- 2How would you build a bulkhead with a Semaphore?
- 3What does CyclicBarrier's barrier action do?
🧩Related Technologies
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?
⭐ Featured Products
Support our platform by exploring our recommended products.
As an Amazon affiliate, purchases through these links may earn us a small commission — at no extra cost to you. It helps keep Full Stack Interview Guru free.