final CountDownLatch latch = new CountDownLatch(1);// 多線程等待計數器 latch.countDown(); //在子線程中減少計數器 try { latch.await();//等待countDown所有完成後,執行後面的代碼 } catch (InterruptedException e) { e.printStackTrace(); }