标签:print ring ace catch cep bsp read system blog
/** * @author t * CyclicBarrier的计数器更像一个阀门, * 需要所有线程都到达, * 然后继续执行,计数器递增,提供reset功能,可以多次使用 */ public class CyclicBarrierDemo { public static void main(String[] args) { CyclicBarrier cyclicBarrier = new CyclicBarrier(7,() -> { System.out.println("线程已全部就绪,准备执行"); } ); for (int i = 1; i <= 7; i++) { final int count = i; new Thread(() ->{ //打印当前线程名称 System.out.println(Thread.currentThread().getName()+" \t"+count+" 号已就绪"); try { cyclicBarrier.await(); }catch (InterruptedException e){ e.printStackTrace(); }catch (BrokenBarrierException e){ e.printStackTrace(); } },String.valueOf(i)).start(); } } }
执行结果
本文来源于 ushowtime https://www.ushowtime.cn/blog/p/48
标签:print ring ace catch cep bsp read system blog
原文地址:https://www.cnblogs.com/ushowtime/p/12496979.html