, ForkJoinPool .
8 core CPU, 8
ForkJoinPool forkJoinPool = new ForkJoinPool(8);
Executor Service FixedThreadPool, Callable,
ExecutorService executorService = Executors.newFixedThreadPool(8);
Future future = executorService.submit(new Runnable() {
public void run() {
System.out.println("Your compute intensive task");
}
});
future.get();
There is one advantage with ForkJoinPool. Idle threads will steal jobs from busy threads from the blokcingQueue where your tasks were sent Runnable/Callable.
Java 8 added another new API in Executors: newWorkStealingPool
If you need to wait for the completion of all tasks, use invokeAll()for ExecutorService.
Take a look at the article on BenjaminAdvanced Parallel APIs Using Java 8
source
share