Quick revision
The short answer
A parallel stream splits its source with the source's Spliterator and runs the chunks as fork-join tasks. By default those tasks run in ForkJoinPool.commonPool(), together with the thread that called the terminal operation. The common pool is one small pool shared by the whole JVM, sized to the number of processors minus one, so in a web server one request doing slow or blocking work in a parallel stream can starve every other request and every CompletableFuture that relies on the same pool.
What to remember
In this answer, we saw that a parallel stream splits its source with the Spliterator's trySplit into fork-join tasks, processes each chunk sequentially and combines the results. The tasks run in ForkJoinPool.commonPool(), whose parallelism defaults to the available processors minus one, with the calling thread helping. Because that pool is shared by the whole JVM, including CompletableFuture's async methods without an executor, blocking or heavy work in one request's parallel stream can starve the others. In server code we default to sequential streams and use our own executors or virtual threads for I/O.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A parallel stream splits its source with the source's Spliterator and runs the chunks as fork-join tasks. By default those tasks run in ForkJoinPool.commonPool(), together with the thread that called the terminal operation. The common pool is one small pool shared by the whole JVM, sized to the number of processors minus one, so in a web server one request doing slow or blocking work in a parallel stream can starve every other request and every CompletableFuture that relies on the same pool.
Why this question is asked
Calling parallelStream() instead of stream() looks like a free speed-up, and in a web server it is one of the easiest ways to make an application slower under load. Interviewers ask this question to check that we know where the extra threads come from, because once we know that, the risks follow naturally. In this answer, we will recap fork-join, follow a parallel stream from split to result, look at the common pool and its size, and then see why sharing it inside a web server causes trouble and what to do instead.
1A Quick Recap of Fork-Join
Fork-join is a way to run a divide-and-conquer job on several threads. A task looks at its piece of work. If the piece is small enough, it does the work directly. If not, it splits it in two, forks one half (schedules it so another thread may pick it up), works on the other half itself, and then joins, which means it waits for the forked half and combines the results.
A ForkJoinPool runs such tasks. Each worker thread has its own queue of tasks. When a worker runs out of work, it steals tasks from the back of another worker's queue. This work stealing keeps all threads busy without a central queue that every thread fights over.
2From Spliterator to Fork-Join Tasks
Every stream source provides a Spliterator, an object that can both walk through the elements and split itself in two. When a terminal operation such as sum or toList runs on a parallel stream, the library wraps the whole job in a fork-join task. The task calls trySplit() on the spliterator to cut off part of the elements, creates a child task for that part, and keeps splitting until each piece is below a target size, roughly the total size divided by four times the pool's parallelism. Each leaf then runs the pipeline sequentially on its piece, and the parent tasks combine the leaf results.
- Terminal operation startsfor example
sum()on a parallel stream - Root task calls trySplit()the spliterator hands half its elements to a new one
- Piece still too large?YesSplit again and fork a child taskNoTreat it as a leaf
- Leaf runs the pipeline sequentiallyfilter, map and so on, on its own chunk
- Parents combine leaf resultsthe caller thread joins and helps while it waits
- Result returned to the caller
6 steps in order. Play them, or step through them one at a time.
Splitting is driven by the source's Spliterator; the work runs on the common pool plus the caller.
Notice the thread names in the second example. Some elements ran on common pool workers and some on main. That is not an accident: the thread that calls the terminal operation does not just wait, it also takes part and processes chunks itself. So a parallel stream uses the caller plus up to parallelism workers from the common pool.
3The Common Pool and Its Size
Unless we do something special, these tasks go to ForkJoinPool.commonPool(), a single static pool created lazily by the JVM. Its parallelism, the number of worker threads it aims to keep busy, defaults to the number of available processors minus one, because the calling thread is expected to help. It is at least one.
In a container, availableProcessors reflects the CPU limit the JVM detects, so a pod limited to 2 CPUs gets a common pool of 1 worker. That surprises people who tested on an 8-core laptop.
The most important fact is that this pool is shared. Every parallel stream in the JVM uses it, and so do CompletableFuture.supplyAsync and runAsync when we do not pass an executor, along with the other async methods of CompletableFuture and some library code. There is one pool for all of them.
4Why This Hurts in a Web Server
A web server handles many requests at once, each on its own thread, typically a Tomcat pool of 200 threads in Spring Boot or virtual threads in newer setups. If ten requests each start a parallel stream, they all submit tasks to the same 7 common pool workers. Each request still gets its own thread's help, but the extra workers are split between all of them, so the expected speed-up shrinks as load grows.
Blocking work makes it much worse. Fork-join assumes tasks compute. If a task inside a parallel stream calls a database or a remote service, the worker thread sits idle waiting for the network, and the pool does not add a thread to replace it. With 7 workers each stuck for 200 milliseconds on an HTTP call, everything else that needs the common pool waits too: other requests' parallel streams, and the CompletableFuture chains that someone wrote with supplyAsync and no executor. One slow downstream service can then stall unrelated features.
6 messages in order. Play them, or step through them one at a time.
The pool is JVM-wide, so one request's blocking work delays everyone else's tasks.
5What to Do Instead
For request-handling code, the safe default is a sequential stream. A web server already gets its parallelism from handling many requests at once; making each request use more threads mostly moves work around and adds contention.
For blocking I/O, such as calling a service for each item, use an executor we control. On Java 21 and later, virtual threads are the natural fit, with a semaphore or a bulkhead to limit how many calls hit the downstream at once.
For CPU-heavy work that really benefits from parallelism, such as a batch job crunching a large array, a parallel stream is fine, ideally measured with JMH first. Changing the common pool's size with the system property affects the whole JVM, so it is the wrong tool to fix one call site.
6Follow-up questions
Can I run a parallel stream in my own ForkJoinPool?
A known trick is to call customPool.submit(() -> list.parallelStream()...toList()).get(), and in current JDKs the stream's tasks then run in that pool. It works because tasks forked from inside a ForkJoinPool worker go to that worker's pool, but it relies on implementation behaviour rather than a documented contract. For blocking work an explicit executor with CompletableFuture or virtual threads is clearer.
Does the common pool add threads when one blocks?
Only when the blocking goes through ForkJoinPool.managedBlock, which some JDK classes use internally. An ordinary socket read or JDBC call does not tell the pool anything, so the worker simply sits blocked and the pool stays short of a thread.
Does CompletableFuture always use the common pool?
The async methods without an executor argument use the common pool, unless its parallelism is below two, in which case they start a new thread per task. Passing our own executor to supplyAsync or thenApplyAsync avoids the shared pool entirely, and in server code we should almost always do that.
7Conclusion
In this answer, we saw that a parallel stream splits its source with the Spliterator's trySplit into fork-join tasks, processes each chunk sequentially and combines the results. The tasks run in ForkJoinPool.commonPool(), whose parallelism defaults to the available processors minus one, with the calling thread helping. Because that pool is shared by the whole JVM, including CompletableFuture's async methods without an executor, blocking or heavy work in one request's parallel stream can starve the others. In server code we default to sequential streams and use our own executors or virtual threads for I/O.
Open with
When I call a terminal operation on a parallel stream, the library wraps the work in a fork-join task. It uses the source's Spliterator, calling trySplit to cut the elements into chunks until they are small enough, runs the pipeline sequentially on each chunk, and combines the partial results up the tree.
Then, if they want more
Those tasks run in ForkJoinPool.commonPool, and the calling thread also takes part rather than just waiting. The common pool's parallelism defaults to the number of available processors minus one, so on an 8-core machine it has 7 workers, and in a container limited to 2 CPUs just 1.
The key point is that it is one pool for the whole JVM: every parallel stream shares it, and so does CompletableFuture's supplyAsync or runAsync when you do not pass an executor. In a web server that is a problem in two ways. Many concurrent requests compete for the same few workers, so the speed-up disappears under load.
And if anyone does blocking work, like HTTP or JDBC calls inside a parallel stream, the workers sit waiting on the network and everything else that needs the pool is starved, including unrelated async code. So in request paths I use sequential streams, and for I/O fan-out an explicit executor, usually virtual threads with a concurrency limit.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- java.util.stream, package documentation, java.util.function, package documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How does a parallel stream run? Which thread pool does it use and why can using it in a...": https://scrivio-interview-library.netlify.app/java/streams/4c5897d72c/