Online Java Compiler By
JavaTpoint.com
import java.util.concurrent.Phaser; public class PhaserGetArrivedPartiesExample1 { public static void main(String[] args) throws InterruptedException { int i, j; Phaser p = new Phaser(); p.register(); int pc = p.getPhase(); System.out.println("Phasecount is "+pc); for(i=1; i<=5;i++) { new PhaserGetArrivedPartiesExample1().testPhaser(p); } Thread.sleep(5000); pc = p.getPhase(); System.out.println("Phasecount is "+pc); j=p.getArrivedParties(); System.out.println("Arrived Parties:"+j); } private void testPhaser(final Phaser phaser) { new Thread(){ @Override public void run() { System.out.println(Thread.currentThread().getName()+" arrived"); } }.start(); } }
Output