JUC辅助类CountDownLatch确保线程有序安全
作者:互联网
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()+"班长锁门走人了");
}
}
标签:JUC,cut,java,currentThread,System,线程,CountDownLatch,out 来源: https://blog.csdn.net/qq_45706306/article/details/122521906