public static void main(String[] args) { CyclicBarrier cyclicBarrier = new CyclicBarrier(2, () -> { System.out.println("===="); }); List<Integer> list = IntStream.rangeClosed(1, 100).boxed().collect(Collectors.toList()); List<List<Integer>> partition = Lists.partition(list, 50); ExecutorService executorService = Executors.newFixedThreadPool(4); for (List<Integer> list1 : partition) { executorService.submit(()->{ try { Thread.sleep(2000); cyclicBarrier.await(); } catch (InterruptedException e) { e.printStackTrace(); } catch (BrokenBarrierException e) { e.printStackTrace(); } }); } }
原文:https://www.cnblogs.com/juncaoit/p/13399313.html