| Refresh | Home EGTry.com

CountDownLatch await block till enough countDown called


CountDownLatch1Test.java

/*
 * Copyright@ 2011 www.egtry.com
 */

package egtry.thread;

import java.util.concurrent.CountDownLatch;

public class CountDownLatch1Test {

  public static void main(String[] args) throws InterruptedException {
	  CountDownLatch latch=new CountDownLatch(2);
	  latch.countDown(); 
	  latch.countDown();
	  latch.await(); //it would block if countDown had not been called twice
	  System.out.println("await call returns successfully");
   

  }
}



Output

await call returns successfully