CountDownLatch并发容器----计数器

其实最重要的就两个方法:

countDown()和await方法;

同时一个线程只能调用countDown()方法或者await()方法,如果调用了await()方法,那么当前线程就阻塞,只能等到其他的线程调完以后才可以正常运行;即:count=0的时机

public CountDownLatch(int count) {
    if (count < 0) throw new IllegalArgumentException("count < 0");
    this.sync = new Sync(count);
}
public void await() throws InterruptedException {
    sync.acquireSharedInterruptibly(1);
}

猜你喜欢

转载自blog.csdn.net/wb_zjp283121/article/details/82380500