feat: CountDownLatch使用
This commit is contained in:
parent
39d2b8b43f
commit
d5f197ce34
|
@ -1,4 +1,24 @@
|
||||||
package cn.bunny.atomic;
|
package cn.bunny.atomic;
|
||||||
|
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
public class AtomicExample04 {
|
public class AtomicExample04 {
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
CountDownLatch latch = new CountDownLatch(2);
|
||||||
|
// 此时为1
|
||||||
|
latch.countDown();
|
||||||
|
System.out.println(latch.getCount());
|
||||||
|
|
||||||
|
// 此时为0
|
||||||
|
latch.countDown();
|
||||||
|
System.out.println(latch.getCount());
|
||||||
|
|
||||||
|
// 还是为0
|
||||||
|
latch.countDown();
|
||||||
|
System.out.println(latch.getCount());
|
||||||
|
|
||||||
|
latch.await();
|
||||||
|
|
||||||
|
System.out.println(latch.getCount());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue