Import Java. util. random; import Java. util. concurrent. cyclicbarrier;/*** cyclicbarrier is similar to countdownlatch and is also a counter. * The difference is that cyclicbarrier calls cyclicbarrier. the number of threads that await () enters the waiting state. * when the number of threads reaches the number specified in the initial state of javasicbarrier, all threads that enter the waiting state are awakened and continue. * Javasicbarrier, like its name, can be seen as an obstacle. * All threads must be completed before they can pass through the obstacle together. * Cyclicbarrier can also contain a runnable parameter at the beginning. * This runnable task is executed before the number of javasicbarrier tasks reaches and all other threads are awakened. */Public class cyclicbarriertest {public static class componentthread implements runnable {cyclicbarrier barrier; // counter int ID; // component ID int [] array; // data array // constructor public componentthread (cyclicbarrier barrier, int [] array, int ID) {This. barrier = barrier; this. id = ID; this. array = array;} public void run () {try {array [ID] = new random (). nextint (100); system. out. println ("component" + ID + "generates:" + array [ID]); // wait for the barrier system here. out. println ("component" + ID + "sleep... "); barrier. await (); system. out. println ("component" + ID + "awaked... "); // calculate the current value in the data array and the subsequent value int result = array [ID] + array [ID + 1]; system. out. println ("component" + ID + "Result:" + result);} catch (exception ex) {}}/ *** test icicbarrier usage */public static void testcyclicbarrier () {final int [] array = new int [3]; javasicbarrier barrier = new javasicbarrier (2, new runnable () {// execute public void run () {system. out. println ("testpolicicbarrier run... "); array [2] = array [0] + array [1] ;}}); // start thread new thread (New componentthread (barrier, array, 0 )). start (); New thread (New componentthread (barrier, array, 1 )). start ();} public static void main (string [] ARGs) {policicbarriertest. testcyclicbarrier ();}}