Skip to content

Instantly share code, notes, and snippets.

@fmamud
Last active August 29, 2015 14:24
Show Gist options
  • Save fmamud/13b08da2a25885cac1fb to your computer and use it in GitHub Desktop.
Save fmamud/13b08da2a25885cac1fb to your computer and use it in GitHub Desktop.
package forkjoin;
import java.math.BigInteger;
import java.util.concurrent.ForkJoinPool;
public class Main {
public static void main(String[] args) {
int n = 50, processors = Runtime.getRuntime().availableProcessors();
System.out.println("Fibonacci num: " + n);
System.out.println("Processors: " + processors);
long time = System.nanoTime();
FibonacciProblem fib = new FibonacciProblem(n);
FibonacciTask fibTask = new FibonacciTask(fib);
ForkJoinPool pool = new ForkJoinPool();
Long result1 = pool.invoke(fibTask);
System.out.println("Result F/J: " + result1);
System.out.println("Time F/J: " + ((System.nanoTime() - time) / 1_000_000) + "ms");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment