随笔记录
JUC-CountDownLatch
2022-3-13 diaba
package com.jiucaiyuan.net.juc.lock;

import java.util.concurrent.CountDownLatch;

/**
* 演示CountDownLatch
* 6个同学陆续离开教室之后,班长才能锁门
*
* @Author jiucaiyuan 2022/3/13 22:40
* @mail services@jiucaiyuan.net
*/

public class CountDownLatchDemo {
public static void main(String[] args) throws InterruptedException {

CountDownLatch countDownLatch = new CountDownLatch(6);

for (int i = 1; i <= 6; i++) {
new Thread(() -> {
System.out.println(Thread.currentThread().getName() + "号同学离开了教室。");
countDownLatch.countDown();
},String.valueOf(i)).start();
}
countDownLatch.await();
System.out.println(Thread.currentThread().getName() + "班长锁门离开了教室。");
}
}
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容