Online Java Compiler By
JavaTpoint.com
import java.util.concurrent.ForkJoinPool; import static java.util.concurrent.ForkJoinTask.invokeAll; import java.util.concurrent.RecursiveTask; import java.util.concurrent.TimeUnit; public class JavaForkJoinPoolisTerminationExample2 { public static void main(final String[] arguments) throws InterruptedException { int proc = Runtime.getRuntime().availableProcessors(); System.out.println("numbers of core available in your processor:" +proc); ForkJoinPool Pool = new ForkJoinPool(proc); Testk t=new Testk(); Pool.awaitTermination(2, TimeUnit.SECONDS); System.out.println(" is terminated :" +Pool.isTerminated() ); } } class Testk extends RecursiveTask
{ @Override protected Integer compute() { Testk t1 = new Testk(); Testk t2 = new Testk(); invokeAll(t1 , t2); return (t1.join() + t2.join()); } }
Output