@@ -0,0 +1,1422 @@
+package sample.jcu.cyclicbarrier;%0A%0Aimport java.util.concurrent.BrokenBarrierException;%0Aimport java.util.concurrent.CyclicBarrier;%0A%0A/**%0A * Cyclic%E6%AF%94CountDownLatch%E5%8A%9F%E8%83%BD%E5%BC%BA%E5%A4%A7,%0A * %E5%8F%82%E6%95%B0parties%EF%BC%8C%E6%BB%A1%E8%B6%B3%E5%90%8E%EF%BC%8C%E4%BC%9A%E9%87%8D%E7%BD%AE%E4%B8%BA0%0A * %E5%A6%82%E6%9E%9C%E7%BA%BF%E7%A8%8B%E6%95%B0 %E5%A4%A7%E4%BA%8E %E5%8F%82%E6%95%B0parties%EF%BC%8Cparties%E4%BC%9A%E8%87%AA%E5%8A%A8%E9%87%8D%E7%BD%AE%EF%BC%8C%E7%BB%A7%E7%BB%AD%E7%AD%89%E5%BE%85parties%E6%BB%A1%E8%B6%B3%E5%90%8E%E6%89%A7%E8%A1%8C%EF%BC%8Crunnable%E6%96%B9%E6%B3%95%EF%BC%9B%0A *%0A *%0A * Created by kanglei on 28/08/2017.%0A */%0Apublic class StudyCyclicBarrier %7B%0A    static class ThreadRunner extends Thread %7B%0A        CyclicBarrier cb=null;%0A        public ThreadRunner(CyclicBarrier cb)%7B%0A            this.cb = cb;%0A        %7D%0A        @Override%0A        public void run() %7B%0A            try %7B%0A//                TimeUnit.SECONDS.sleep(2);%0A                System.out.println(Thread.currentThread().getName()+%22 %E5%88%B0%E4%BA%86%E3%80%82%22);%0A                this.cb.await();%0A            %7D catch (InterruptedException e) %7B%0A                e.printStackTrace();%0A            %7D catch (BrokenBarrierException e) %7B%0A                e.printStackTrace();%0A            %7D%0A%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        final CyclicBarrier cb=new CyclicBarrier(2, new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                System.out.println(%22OK,%E9%83%BD%E5%88%B0%E9%BD%90%E4%BA%86,%E6%88%91%E4%BB%AC%E5%87%86%E5%A4%87%E4%B8%8B%E4%B8%80%E6%AD%A5%22);%0A            %7D%0A        %7D);  //%E4%B8%89%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%97%B6%E5%88%B0%E8%BE%BE%0A        ThreadRunner%5B%5D runners = new ThreadRunner%5B13%5D;%0A        for (int i = 0; i %3C runners.length; i++) %7B%0A            runners%5Bi%5D = new ThreadRunner(cb);%0A            runners%5Bi%5D.setName(%22%E8%BF%90%E5%8A%A8%E5%91%98-%22+i);%0A            runners%5Bi%5D.start();%0A        %7D%0A%0A    %7D%0A%7D%0A

add cyclicbarrier demo