多个线程都完成才执行主线程
public static void test1() throws InterruptedException { //初始化线程数量 CountDownLatch countDownLatch=ThreadUtil.newCountDownLatch(5); for(int i=0;i<5;i++){ ThreadUtil.execute(() -> { try { Thread.sleep(6000); System.out.println("111" ); //调用线程计数器-1 countDownLatch.countDown(); } catch (InterruptedException e) { e.printStackTrace(); } }); } //唤醒主线程 try { countDownLatch.await(); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("完成"); }