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