Package cn.tool;
Import java.util.concurrent.BrokenBarrierException;
Import Java.util.concurrent.CyclicBarrier;
Import Java.util.concurrent.ExecutorService;
Import java.util.concurrent.Executors;
Import Java.util.concurrent.Semaphore; public class Cyclicbarriertest {/** * java5 Sync Tool * When all threads arrive at a specified location to continue executing/public static void Mai
N (string[] args) {//will create 3 threads Executorservice Pool=executors.newcachedthreadpool () based on the 3 tasks created;
Final Cyclicbarrier cb=new Cyclicbarrier (3); for (int i=0;i<3;i++) {Runnable ren=new Runnable () {@Override public void
Run () {try {thread.sleep (200);
System.out.println (Thread.CurrentThread (). GetName () + "reached rendezvous point 1");
Cb.await ()//////////(202) After all threads have arrived; Thread.Sleep System.out.println (Thread.CurrentThread (). GetName () + "reached rendezvous point 2");
Cb.await ()//////////(202) After all threads have arrived; Thread.Sleep
System.out.println (Thread.CurrentThread (). GetName () + "reached rendezvous point 3");
catch (Interruptedexception e) {e.printstacktrace (); catch (Brokenbarrierexception e) {//TODO auto-generated catch block E.
Printstacktrace ();
}
}
};
Pool.execute (ren);
} pool.shutdown ();
}
}