Online Java Compiler By
JavaTpoint.com
import java.util.concurrent.Phaser; public class PhaserForceTerminationExample2 { public static void main(String[] args) throws InterruptedException { Phaser p = new Phaser(); p.register(); System.out.println("Phaser Object is register..."); int i; for(i=0; i<=5; i++) { new PhaserForceTerminationExample2().test(p); } } private void test(final Phaser p) { new Thread(){ @Override public void run() { try { System.out.println(Thread.currentThread().getName()+" arrived"); } finally{ System.out.println(Thread.currentThread().getName()+" Terminated:"); p.forceTermination(); } } }.start(); } }
Output