+/EE360P
distributed systems
git clone https://git.julia.blue/+/EE360P
cbff598
master
1public class testCyclicBarrier implements Runnable { 2final static int SIZE =5 ; 3final static int ROUND =5 ; 4 5final MonitorCyclicBarrier gate ; 6 7public testCyclicBarrier (MonitorCyclicBarrier gate ) {this .gate =gate ; } 8 9public void run () { 10int index = -1 ; 11 12for (int round =0 ;round <ROUND ; ++round ) { 13System .out .println ("Thread " +Thread .currentThread ().getId () + 14" is WAITING round:" +round ); 15try { 16index =gate .await (); 17 }catch (InterruptedException e ) {e .printStackTrace (); } 18System .out .println ("Thread " +Thread .currentThread ().getId () + 19" is leaving round:" +round ); 20 } 21 } 22 23public static void main (String []args ) { 24MonitorCyclicBarrier gate =new MonitorCyclicBarrier (SIZE ); 25Thread []t =new Thread [SIZE ]; 26 27for (int i =0 ;i <SIZE ; ++i ) { 28t [i ] =new Thread (new testCyclicBarrier (gate )); 29 } 30 31for (int i =0 ;i <SIZE ; ++i ) {t [i ].start (); } 32 } 33}