不是同时启动的,但是线程都会阻塞在latch.await这里,直到最后一层循环,latch.countdown所有的线程被唤醒开始执行。
public class MJ {
static CountDownLatch latch = new CountDownLatch(100);
public static void main(String[] args) throws InterruptedException {
for (int i = 0; i < 100; i++) {
new Thread(() -> {
try {
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.println("凛苏");
}).start();
latch.countDown();
}
}
}