Online Java Compiler By
JavaTpoint.com
import java.util.concurrent.Phaser; public class JavaPhaserRegisterExample2 { public static void main(String[] args) throws InterruptedException { Phaser p = new Phaser(); p.register(); System.out.println("Phaser Object is register..."); int pc = p.getPhase(); System.out.println("Initial Phase count is "+pc); System.out.println("Thread is sleeping"); Thread.sleep(5000); new JavaPhaserRegisterExample2().test(p); new JavaPhaserRegisterExample2().test(p); new JavaPhaserRegisterExample2().test(p); new JavaPhaserRegisterExample2().test(p); 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"); p.arriveAndAwaitAdvance(); } }.start(); } }
Output