CKTIS / Java
ForkJoinPool.commonPool — the shared task pool
ForkJoinPool.commonPool() returns the shared fork/join pool, rather than creating a new pool for each call.
Version: Java SE 21; repository runtime, production runtime not attested
Syntax
public static ForkJoinPool commonPool()ForkJoinPool.commonPool() is a static method returning the shared ForkJoinPool instance. The pool uses work-stealing: worker threads take available tasks. Shared resources mean that long-running tasks can delay other tasks.
Calling shutdown(), shutdownNow(), or close() does not shut down the common pool; close() does not wait either. Workers are daemon threads, so explicitly wait for required results before program exit.
The example uses submit() and join() to obtain the result before printing. For blocking I/O, the pool does not guarantee compensation for blocked workers. A custom pool provides resource separation.
Examples
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
public class Main {
public static void main(String[] args) {
ForkJoinPool pool = ForkJoinPool.commonPool();
ForkJoinTask<Integer> result = pool.submit(() -> 6 * 7);
System.out.println(result.join());
}
}Result
42
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.