What is the ForkJoinPool common pool, who shares it, and why does blocking work on it cause problems?
answer
- commonPool() = one JVM-wide shared ForkJoinPool
- Parallelism = cores − 1; daemon threads
- Parallel streams + CompletableFuture default-async use it
- Blocking on it starves other users → stalls/deadlock
- Fixes: own Executor, separate/virtual-thread pool, ManagedBlocker
basics
~20 sThe common pool is a single ForkJoinPool the JVM shares process-wide. Parallel streams and CompletableFuture's default async methods run on it. Its parallelism is the CPU count minus one, so blocking tasks on it can starve unrelated code that uses it.
solid answer
~50 sForkJoinPool.commonPool() is a lazily-initialised, JVM-wide shared pool whose daemon worker threads start on demand. By default its parallelism is the number of available processors minus one, never below 1, because a caller that joins a common-pool task helps run subtasks. It is the default execution context for parallel streams and for CompletableFuture's async methods that take no Executor; since JDK 25 those always use it, where earlier releases started a thread per task when its parallelism was below 2. Being shared and small, it suits short, CPU-bound, non-blocking tasks. Blocking work (I/O, locks, sleeps) ties up its few threads, and unrelated parallel streams and CompletableFutures stall. Fixes: pass a dedicated Executor to the *Async overloads, run blocking work on a separately sized pool or virtual threads, and wrap unavoidable waits in a ManagedBlocker so the pool can add a spare thread before it stalls.
go deeper
Knows the common pool is a shared thread pool and that parallel streams use it; understands you shouldn't fill it with slow blocking work.
Can name the common pool's default size (cores − 1) and that both parallel streams and default CompletableFuture async run on it, and knows to pass a custom Executor for blocking work.
Explains the starvation/deadlock mechanism when blocking on the shared cores-sized pool and the concrete fixes (dedicated executor, separate sizing, ManagedBlocker).
Reasons about cross-feature interference from a shared pool at service scale, sizing the common pool (setParallelism, or the system property its Javadoc now discourages), and choosing virtual threads vs Fork/Join for blocking-heavy workloads.
## What the common pool is `ForkJoinPool.commonPool()` returns a **single, process-wide ForkJoinPool** that the JVM creates lazily on first use; its worker threads start on demand, are slowly reclaimed when idle and come back on later use. "Common" = *shared by everyone in the JVM*. It exists so that code wanting parallelism doesn't each spin up its own pool (which would oversubscribe the CPU with far more threads than cores). Key defaults: - **Parallelism = available processors − 1, at least 1.** On an 8-core machine the target is 7 workers; on a one- or two-core machine it is 1. The "−1" works because a thread that *waits on a join* (as a parallel stream's terminal operation does) helps run subtasks, so total ≈ core count; tasks handed in through the `ExecutorService` submission methods get no such help. - **Daemon threads.** Its workers are daemon threads, so they don't keep the JVM alive — the process can exit even if common-pool threads exist. - **Unaffected by `shutdown()`, `shutdownNow()` and `close()`**; it is terminated only when the program exits. - **Configurable**, with care: the system property `java.util.concurrent.ForkJoinPool.common.parallelism` still works, but its Javadoc now discourages it in favour of `ForkJoinPool.setParallelism` (JDK 19); `java.util.concurrent.ForkJoinPool.common.maximumSpares` caps the extra threads it may add for blocked workers (default 256). ## Who shares it (this is the trap) Two very common features run on the common pool *by default*, often without developers realising: 1. **Parallel streams.** `collection.parallelStream()` / `stream().parallel()` execute their pipeline on the common pool. There is no parameter to choose a pool — they always use the common pool (short of an undocumented trick of running the terminal op inside your own ForkJoinPool). 2. **CompletableFuture async methods without an Executor.** `CompletableFuture.supplyAsync(supplier)`, `thenApplyAsync(fn)`, etc. — the overloads that **don't** take an `Executor` — run on the common pool. Since **JDK 25** that holds at any parallelism; before 25, a common pool with parallelism below 2 (any machine with one or two processors) made them start a new thread per task instead. So a single small pool is multiplexed across unrelated parts of your application. ## Why blocking on it is dangerous The pool is sized to **cores**, and Fork/Join assumes tasks are **short and CPU-bound**. A worker that **blocks** (waits on a network call, a lock, `Thread.sleep`, a database round-trip, or a `Future` whose work is queued on the *same* pool) occupies one of those few threads while doing nothing useful. Block enough workers and the pool has no free threads: - Other parallel streams elsewhere in the app stall. - Other CompletableFuture stages queue up and don't run. - In the worst case you get a **deadlock**: a common-pool task waits, through a plain blocking call, for another task that can only run on the common pool, but every worker is already blocked waiting. Waits the pool knows about (`ForkJoinTask.join()`, `CompletableFuture.get()`/`join()`, untimed `Condition` waits) let it add spare threads instead, up to the `maximumSpares` cap. Because the symptom appears in *unrelated* code that merely shares the pool, these bugs are hard to localise. ## The fixes 1. **Give CompletableFuture its own Executor.** Always prefer the `*Async(fn, executor)` overloads with a dedicated, appropriately-sized `Executor` for any blocking or long-running stage. Don't let blocking work land on the common pool. 2. **Don't run blocking work in parallel streams.** Parallel streams are for CPU-bound aggregation. For blocking fan-out, use an explicit executor (or virtual threads) instead. 3. **Size a separate pool for blocking work.** A pool tuned to your I/O concurrency (often many more threads than cores) — or **virtual threads** (Java 21+), which are cheap and designed to block — is the right tool for blocking workloads. 4. **ManagedBlocker for unavoidable blocking.** If you must block inside a ForkJoinPool, wrap it in **`ForkJoinPool.ManagedBlocker`** and call it via `ForkJoinPool.managedBlock(...)`. This tells the pool the worker is about to block, so it can **wake an idle worker or start a temporary spare thread**. In JDK 25 and 27 it grows past its parallelism by default only when the pool could otherwise stall for lack of unblocked workers, so it protects progress rather than full parallelism. It mitigates starvation but doesn't make blocking *cheap*. ## Mental model The common pool is a small shared kitchen with one cook per stove (≈ cores). Parallel streams and CompletableFutures all send orders to that same kitchen. If one order makes a cook stand and wait by the phone (blocking), that stove is dead — and since there are only as many stoves as cores, a few waiting cooks bring the whole kitchen to a halt for *everyone*.
- How do you keep a blocking CompletableFuture stage off the common pool?Use the *Async overloads that take an Executor — e.g. supplyAsync(task, myExecutor) or thenApplyAsync(fn, myExecutor) — passing a dedicated, appropriately-sized pool (or a virtual-thread executor). The no-Executor overloads default to the common pool.
- What does ForkJoinPool.ManagedBlocker do for you?It tells the pool a worker is about to block, so the pool can wake an idle worker or start a spare thread while that worker is parked. In JDK 25 and 27 it grows past its parallelism by default only when the pool could otherwise stall for lack of unblocked workers, so it guards progress rather than holding full parallelism; the common pool allows up to 256 spares by default.
- Thinking parallel streams use a fresh pool per stream — they share one common pool
- Believing each CompletableFuture gets its own threads — the no-Executor overloads use the common pool
- Running blocking I/O on a parallel stream or default-async CompletableFuture and expecting isolation
- Assuming the common pool grows to absorb blocked I/O — it adds spares only for blocked joins and ManagedBlocker waits
- Calling shutdown() on the common pool (it's meant to live for the JVM and ignores shutdown)
- ForkJoinPool common pool
- Java 1.8
- parallel streams
- Java 1.8
- CompletableFuture
- Java 1.8
Checked against JDK 27 and the same at JDK 25 LTS. JDK 25 made CompletableFuture's no-Executor async methods always use the common pool; before it, a common-pool parallelism below 2 meant a new thread per task.
context
- ForkJoinPool (Java SE 27 & JDK 27)docs.oracle.com
- CompletableFuture (Java SE 27 & JDK 27)docs.oracle.com
- ForkJoinTask (Java SE 27 & JDK 27)docs.oracle.com