Name
CountDownLatch
Synopsis
This class
synchronizes
threads. All threads that call await( ) block
until the countDown( ) method is invoked a
specified number of times. The required number of calls is specified
when the CountDownLatch is created. Once
countDown( ) has been called the required number
of times, all threads blocked in await( ) are
allowed to resume, and any subsequent calls to await(
) do not block. getCount( ) returns the
number of calls to countDown( ) that must still be
made before the threads blocked in await( ) can
resume. Note that there is no way to reset the count. Once a
CountDownLatch has
“latched,” it remains in that state
forever. Create a new CountDownLatch if you need
to synchronize another group of threads. Contrast this class with
CyclicBarrier.
public class CountDownLatch { // Public Constructors public CountDownLatch(int count); // Public Instance Methods public void await( ) throws InterruptedException; public boolean await(long timeout, TimeUnit unit) throws InterruptedException; public void countDown( ); public long getCount( ); // Public Methods Overriding Object public String toString( ); }
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access