package futures; import java.util.concurrent.*; public class FibExec2 { final static ExecutorService exec = new MyExecutor(8); // final static ExecutorService exec = new ForkJoinPool(8); static int fcall(int n) throws Exception { if (n < 2) return n; Future f1 = exec.submit(() -> fcall(n - 1)); int n2 = fcall(n - 2); return f1.get() + n2; } public static void main(String[] args) throws Exception { for (int n = 0; n <= 47; n++) { long t1 = System.currentTimeMillis(); int f = fcall(n); long t2 = System.currentTimeMillis(); double tm = 1e-3*(t2-t1); System.out.printf("fib(%d)=%d, time=%f%n", n, f, tm); } exec.shutdown(); } }