CountDownLatch
A CountDownLatch is a synchronization aid in Java that allows one or more threads to wait until a set of operations performed by other threads completes. It is initialized with a count, which represents the number of events that must occur before the waiting threads can proceed. Each time an event occurs, the count is decremented, and when it reaches zero, all waiting threads are released.
This mechanism is useful in scenarios where a task needs to wait for multiple threads to finish their work before continuing. For example, a main thread can use a CountDownLatch to wait for several worker threads to complete their tasks before proceeding with the next steps in a program.