Online Java Compiler By
JavaTpoint.com
import java.util.concurrent.Phaser; public class JavaPhaserGetPhaseExample1 { public static void main(String[] args) throws InterruptedException { Phaser p = new Phaser(10); p.register(); int pc = p.getPhase(); System.out.println("Initial Phase count is "+pc); System.out.println("Thread is sleeping"); for(int i=0; i<=10; i++) { new JavaPhaserGetPhaseExample1().test(p); p.arrive(); } pc = p.getPhase(); System.out.println("Final Phase count after arrival of Thread is "+pc); } void test(final Phaser p) { new Thread(){ @Override public void run() { System.out.println(Thread.currentThread().getName()+" arrived"); } }.start(); } }
Output