CountDown计数器减一方法,await方法线程等待阻塞,变为零继续执行
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
public class Asd {
public static void main(String []args) throws InterruptedException {
CountDownLatch cut=new CountDownLatch(6);//juc辅助类
for(int i=1;i<=6;i++) {
new Thread(()->{System.out.println(Thread.currentThread().getName()+"号同学离开了教室");
cut.countDown();},String.valueOf(i)).start();
}
cut.await();
System.out.println(Thread.currentThread().getName()+"班长锁门走人了");
}
}