线程全部结束与集合点
final int size = 50;final CountDownLatch countDown = new CountDownLatch(size);//执行计数final CyclicBarrier barrier = new CyclicBarrier(size); //集合点ExecutorService exec = Executors.newFixedThreadPool(size); long start = System.currentTimeMillis();for(int index=1; index <= size; index++ ){ final int indexCopy = index; Runnable run = new Runnable() { public void run() { try { System.out.println(indexCopy+"号就绪!"); barrier.await();//等待所有线程集合 System.out.println(indexCopy+"号开始执行!"); } catch (Exception e) { e.printStackTrace(); } finally{ countDown.countDown();//释放 } } }; exec.execute(run); } countDown.await();//等待线程完成 exec.shutdown(); //统计时间 System.out.println("结束时间:"+sdf.format(endDate));