Completion, rendezvous and phased work
Definition:
A synchronizer coordinates when threads can proceed without polling blindly.
Explanation:
CountDownLatch is one-shot and callers can use it to observe completion without assuming success.
Illustration image:
Example:
var completed = new java.util.concurrent.CountDownLatch(2);
Runnable task = () -> {
try { loadShard(); }
finally { completed.countDown(); }
};Expected behavior. Two task exits unblock a waiter. Record exceptions separately because countdown does not report success.
Internal working:
CyclicBarrier is reusable for a fixed party count, and a failed wait can break the current generation. Phaser supports dynamic registration and per-phase advancement; deregister workers that will not participate again.
Interview questions:
Does CountDownLatch report whether all tasks succeeded?
No. It reports that the count reached zero. Collect task failures independently.