ExecutorService — general-purpose thread pool for task execution. ForkJoinPool — specialized pool for divide-and-conquer tasks using work-stealing.
1// ExecutorService2ExecutorService executor = Executors.newFixedThreadPool(4);3executor.submit(() -> doWork());4executor.shutdown();56// ForkJoinPool7ForkJoinPool pool = new ForkJoinPool(4);8ForkJoinTask<Long> task = new RecursiveTask<Long>() {9 protected Long compute() {10 if (size <= THRESHOLD) {11 return sequentialCompute();12 }13 ForkJoinTask<Long> left = subtask(leftHalf).fork();14 Long right = subtask(rightHalf).compute();15 Long leftResult = left.join();16 return combine(leftResult, right);17 }18};
Key differences: