CountDownLatch and CyclicBarrier are synchronization utilities from the java.util.concurrent package, but they serve different purposes. CountDownLatch allows one or more threads to wait until a specific number of operations are completed, whereas CyclicBarrier enables a group of threads to wait for each other at a common execution point before continuing. A CountDownLatch can be used only once, while a CyclicBarrier can be reused multiple times.
In an application startup process, the main thread may wait for database, cache, and messaging services to initialize using CountDownLatch. In contrast, a parallel data-processing application may use CyclicBarrier to ensure all worker threads complete one stage before moving to the next stage.
import java.util.concurrent.CountDownLatch;
public class Main {
public static void main(String[] args)
throws Exception {
CountDownLatch latch =
new CountDownLatch(3);
for (int i = 1; i <= 3; i++) {
new Thread(() -> {
System.out.println(
"Task Completed");
latch.countDown();
}).start();
}
latch.await();
System.out.println(
"All Tasks Finished");
}
}A concise interview answer is: CountDownLatch is used when one or more threads need to wait for a fixed number of tasks to complete and can be used only once. CyclicBarrier is used when multiple threads must wait for each other at a common point and can be reused across multiple synchronization cycles.
Last updated: 16 July 2026
Previous question: What is a DDoS (distributed denial-of-service) attack, and how can applications be protected from it?
Next question: How does the introduction of the module system in Java 9 impact application architecture?