public class CountDownLatchTest {
    static CountDownLatch c=new CountDownLatch(2);

    public static void main(String[] args) throws InterruptedException {
       new Thread(new Runnable() {
           @Override
           public void run() {
               System.out.println(1);
               c.countDown();
               System.out.println(2);
               c.countDown();
           }
       }).start();
       c.await();
        System.out.println(3);
    }
}


(1) * CountDownLatch的构造函数接受一个int类型的参数作为计数器,如果想要等待N个点完成,就传入N。 * 当调用CountDownLatch的countDown方法时,N会减1. * CountDownLatch中的await()方法会阻塞当前线程直到N变为0 * 这里可以是N个线程也可以是一个线程里的N个执行步骤。 * 用在多个线程时,只需要把CountDownLatch引用传递到线程即可


(2)


/* * await(long time,TimeUnit unit):带有等待时间的await * */


(3)


/* * 计数器的值必须大于等于0,如果等于0 ,调用await方法时不会阻塞当前线程。 * */


(4)


/* * CountDownLatch不可能重新初始化或者修改CountDownLatch对象内部计数器的值 * */