Quick revision
The short answer
Both supplyAsync without an executor and parallel streams run on ForkJoinPool.commonPool(), whose parallelism is usually the number of available processors minus one, often just 3 workers in a 4-CPU container. The blocking HTTP calls occupy those few workers, so parallel streams and every other async task wait for a free one. The fix is to pass a dedicated executor sized for I/O to supplyAsync, or a virtual-thread executor with a concurrency limit; and note that when the common pool's parallelism is below 2, CompletableFuture uses a new thread per task instead.
What to remember
In this answer, we saw why both features slow down together: supplyAsync without an executor and parallel streams share ForkJoinPool.commonPool(), which usually has only processors minus one workers, and blocking HTTP calls hold those workers while the CPU sits idle. Passing a dedicated executor, virtual threads with a concurrency limit or a bounded pool sized for I/O, keeps blocking work off the common pool, and it also avoids the special case where CompletableFuture starts a new thread per task when the common pool's parallelism is below 2.
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.
Both supplyAsync without an executor and parallel streams run on ForkJoinPool.commonPool(), whose parallelism is usually the number of available processors minus one, often just 3 workers in a 4-CPU container. The blocking HTTP calls occupy those few workers, so parallel streams and every other async task wait for a free one. The fix is to pass a dedicated executor sized for I/O to supplyAsync, or a virtual-thread executor with a concurrency limit; and note that when the common pool's parallelism is below 2, CompletableFuture uses a new thread per task instead.
Why this question is asked
This is one of the most common performance surprises in Java services, because both pieces of code look harmless and are written in different places, often by different people. Under light load they are fast; under real load both become slow together, and nothing in the code connects them. Interviewers ask it to see whether we know what runs our async code by default. In this answer, we will recap the common pool, reproduce the slowdown, see why blocking calls starve everything else, fix it with an explicit executor, and look at the special case of very small machines.
1A Quick Recap of the Common Pool
ForkJoinPool.commonPool() is a single ForkJoinPool shared by the whole JVM. It was added in Java 8 so that parallel streams and asynchronous methods would work without anyone having to create and size a pool. Its parallelism, the number of worker threads it aims to keep busy, is by default the number of available processors minus one, because the thread that starts a parallel stream also helps with the work.
Two APIs in the question use it. CompletableFuture.supplyAsync(supplier) without an executor argument runs the supplier on the common pool. A parallel stream splits its data into chunks and processes them as tasks on the common pool. So in this service, both features share the same few threads.
2Reproducing the Slowdown
Let us simulate the service under load. Requests arrive and each starts one async HTTP call that takes 500 ms because the remote service is slow today. Elsewhere, another endpoint filters a list with a parallel stream, which normally takes 20 ms.
Notice that endpoint B never calls the remote service, and still it becomes slow. That is the clue that a shared resource is involved.
3Why Blocking Calls Starve Everything Else
Little's law tells us how many workers the HTTP calls need: 30 calls per second times 0.5 seconds is 15 calls in flight. The common pool has 3 workers. So the HTTP calls alone need five times more threads than exist, and a queue of async tasks builds up in the pool. Each blocked worker is just waiting on a socket, using no CPU, but the pool has no idea; it was designed for CPU-bound tasks and does not add threads for ordinary blocking I/O.
Now endpoint B's parallel stream submits its chunks to the same pool. They go into the same queues and wait behind the HTTP tasks, or wait for a worker to become free. The calling thread of the stream does help with its own chunks, so the stream still makes some progress, but most of its parallel work is stuck. Any other code that uses the common pool, including libraries, slows down too.
| Worker | Doing | Uses CPU? |
|---|---|---|
commonPool-worker-1 | restClient.get(url): waiting on socket | no |
commonPool-worker-2 | restClient.get(url): waiting on socket | no |
commonPool-worker-3 | restClient.get(url): waiting on socket | no |
| queue | 12 more HTTP tasks, B's stream chunks, other callbacks | waiting |
4The Fix: An Executor Sized for I/O
Blocking work needs threads that are allowed to block. We create a dedicated executor for the HTTP calls and pass it to supplyAsync, which has an overload for exactly this. On Java 21 and later, a virtual-thread executor is the natural choice, because a blocked virtual thread costs almost nothing; we add a limit on concurrent calls so we do not flood the remote service. On older JDKs, a bounded ThreadPoolExecutor sized by Little's law does the same job.
Notice that the remote service is still slow, so endpoint A is still 500 ms. But that slowness no longer spreads: endpoint B is back to 20 ms because the common pool is free for the CPU-bound work it was designed for. We also add a timeout to the HTTP call itself, so blocked threads come back even if the remote hangs.
The same rule applies to the later stages. thenApply on the returned future may run on whatever thread completes it; if a callback does blocking work, use thenApplyAsync(fn, executor) with the I/O executor too.
5A Special Case: Very Small Machines
On a machine or container that reports 1 or 2 processors, the common pool's parallelism is 0 or 1. CompletableFuture handles this case specially: when the common pool's parallelism is below 2, its default async executor is not the common pool at all but one that creates a new thread for every task. So on a 1-CPU container, every supplyAsync without an executor starts a brand-new platform thread, which is expensive under load in its own way and makes behaviour differ between a developer laptop and production. Parallel streams on such a machine get little or no parallelism.
This is one more reason to pass an explicit executor: the behaviour is then the same on every machine, and we can see and measure it.
6Follow-up questions
How would you confirm the common pool is the problem in production?
Take a thread dump and look at the ForkJoinPool.commonPool-worker threads. If they are all inside socket reads, HTTP clients or JDBC calls, blocking work has taken the pool. The pool's getQueuedSubmissionCount() and getActiveThreadCount() can also be exposed as metrics.
Why not just raise the common pool's parallelism?
The system property java.util.concurrent.ForkJoinPool.common.parallelism can raise it, but that changes the pool for every user in the JVM, makes CPU-bound streams run with too many threads, and only moves the limit. Giving blocking work its own executor fixes the cause.
Does the asynchronous HttpClient in the JDK have the same problem?
java.net.http.HttpClient.sendAsync does not block a thread while waiting for the response, and its callbacks run on the client's own executor, which defaults to a pool created per client rather than the common pool. The problem in the question comes from wrapping a blocking client call in supplyAsync.
7Conclusion
In this answer, we saw why both features slow down together: supplyAsync without an executor and parallel streams share ForkJoinPool.commonPool(), which usually has only processors minus one workers, and blocking HTTP calls hold those workers while the CPU sits idle. Passing a dedicated executor, virtual threads with a concurrency limit or a bounded pool sized for I/O, keeps blocking work off the common pool, and it also avoids the special case where CompletableFuture starts a new thread per task when the common pool's parallelism is below 2.
Open with
Both pieces of code run on the same threads. supplyAsync without an executor uses ForkJoinPool.commonPool, and parallel streams use it too. The common pool is one shared pool for the whole JVM, and its parallelism is by default the number of available processors minus one, so in a four-CPU container that is three workers.
Then, if they want more
The supplier here is a blocking HTTP call. Under load, say 30 calls per second at 500 milliseconds, we need about 15 threads in flight, but there are three, and the pool does not add threads for plain blocking I/O, because it was designed for CPU-bound tasks.
So all three workers sit waiting on sockets, async tasks queue up, and the parallel streams elsewhere wait for a worker even though they never call the remote service. A thread dump would show every commonPool worker inside a socket read.
The fix is to pass an executor meant for blocking work as the second argument to supplyAsync: on Java 21 a virtual-thread-per-task executor plus a semaphore to limit concurrent calls, or on older versions a bounded ThreadPoolExecutor sized by Little's law, with a timeout on the call. Callbacks that block should use the async variants with that executor too.
Then the remote service is still slow, but only for that endpoint, and the parallel streams are fast again. One more detail: if the common pool's parallelism is below two, CompletableFuture uses a new thread per task instead, so passing an executor also makes behaviour consistent across machines.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21, Java 8
- 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.concurrent, package documentation, JLS chapter 17, Threads and Locks
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 "A service uses CompletableFuture.supplyAsync(() -> restClient.get(url)) without an...": https://scrivio-interview-library.netlify.app/java/executors/d2c5709d77/