From the course: Parallel and Concurrent Programming with Java 2

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

CountDownLatch: Java demo

CountDownLatch: Java demo - Java Tutorial

From the course: Parallel and Concurrent Programming with Java 2

Start my 1-month free trial

CountDownLatch: Java demo

- [Instructor] In addition to the CyclicBarrier, Java provides another related synchronization mechanism called a CountDownLatch that allows one or more threads to wait until a set of operations being performed in other threads completes. The CountDownLatch is initialized with a given count value. Threads can then either wait at the latch until that count value reaches zero, much like how threads can wait at a CyclicBarrier, or they can decrement the count value by invoking the countDown method. So the key difference between a CountDownLatch and a CyclicBarrier is that the CyclicBarrier releases when a certain number of threads are waiting on it. Whereas the CountDownLatch releases after the countDown method gets called enough times to reduce the count value to zero. Additionally, the CountDownLatch is a one-shot mechanism and cannot reset the count value. If you need to reset that countDown value, you'll just need to create a new latch object. To demonstrate the CountDownLatch in…

Contents