Online Java Compiler By
JavaTpoint.com
import java.util.concurrent.Phaser; public class PhaserBulkRegisterExample2 { public static void main(String[] args) throws InterruptedException { Phaser p = new Phaser(); p.register(); int pc = p.getPhase(); System.out.println("Phasecount is "+pc); new PhaserBulkRegisterExample2().test(p); System.out.println("Unarrived parties to current phaser : "+p.bulkRegister(0)); new PhaserBulkRegisterExample2().test(p); System.out.println("Unarrived parties to current phaser : "+p.bulkRegister(1)); Thread.sleep(5000); pc = p.getPhase(); System.out.println("Phasecount is "+pc); } private void test(final Phaser phaser) { new Thread(){ @Override public void run() { try{ System.out.println(Thread.currentThread().getName()+" arrived"); } catch(IllegalArgumentException e) {} } }.start(); } }
Output