Online Java Compiler By
JavaTpoint.com
import java.util.concurrent.Phaser; public class PhaserGetRootExample2 { 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=0;i<=5;i++) { new PhaserGetRootExample2().testPhaser(p); if(i==3) { new PhaserGetRootExample2().testPhaser(p); System.out.println("Root : "+p.getRoot()); } } System.out.println("Root : "+p.getRoot()); Thread.sleep(5000); pc = p.getPhase(); System.out.println("Phasecount is "+pc); } private void testPhaser(final Phaser phaser) { new Thread(){ @Override public void run() { System.out.println(Thread.currentThread().getName()+" arrived"); } }.start(); } }
Output