Scrivio Interview library
InternalsIntermediate6 min read · updated 12 November 2026

How is the virtual thread scheduler configured, and when would you change it?

The default virtual thread scheduler is a ForkJoinPool in FIFO mode whose parallelism, the number of carriers normally running, defaults to the number of available processors. Two system properties adjust it: jdk.virtualThreadScheduler.parallelism sets that number, and jdk.virtualThreadScheduler.maxPoolSize caps how many carriers can exist when the pool temporarily adds extra ones to compensate for operations that pin or capture a carrier. Changing them rarely helps, because CPU-bound work is limited by cores anyway, and as of Java 25 there is no supported public API to plug in a custom scheduler.

Why this question is asked

Teams adopting virtual threads often look for a knob to turn when something performs badly, and the scheduler properties are the obvious candidates. Knowing what they really control, and why the defaults are almost always right, saves a lot of misguided tuning. Interviewers ask this to see whether we understand the scheduler well enough to know when not to touch it. In this answer, we will recap what the scheduler does, look at its configuration properties, explain compensation and maxPoolSize, go through the few situations where changing the settings makes sense, and close with the custom scheduler question.

1A Quick Recap of the Scheduler

Virtual threads need carriers, platform threads that actually execute their code. The scheduler owns those carriers and decides which runnable virtual thread runs on which carrier. In the JDK, the default scheduler is a ForkJoinPool, the same work-stealing pool used by parallel streams, but a separate instance running in FIFO mode, so virtual threads that become runnable are generally run in the order they were submitted rather than the most recent first.

Its parallelism is the number of carriers it aims to keep running at the same time. By default this equals Runtime.getRuntime().availableProcessors(), which in a container respects the CPU limit the JVM detects. On a container limited to 4 CPUs, the scheduler normally runs 4 carriers.

2The Configuration Properties

The scheduler is configured with system properties at JVM startup; it cannot be changed while the application runs.

Java
# defaults on a 4-CPU container (check your JDK version for exact defaults)
java -Djdk.virtualThreadScheduler.parallelism=4 \
-Djdk.virtualThreadScheduler.maxPoolSize=256 \
-jar app.jar
# parallelism : carriers normally running default = availableProcessors() -> 4
# maxPoolSize : upper bound including extra ones default = max(parallelism, 256) -> 256
Scheduler properties
PropertyMeaningDefault
jdk.virtualThreadScheduler.parallelismcarriers normally runningavailable processors
jdk.virtualThreadScheduler.maxPoolSizecap including compensating carriersmax(parallelism, 256)
Set at startup only; check your JDK version for exact defaults.

parallelism is the number that matters day to day: it is how many virtual threads can execute Java code at the same instant. maxPoolSize is a safety limit, not a target. Most of the time the pool has exactly parallelism carriers; it grows above that only to compensate, as the next section explains. There is also a minimum-runnable setting in some versions; check your JDK documentation, since these properties are implementation details rather than a standard API.

3Compensation: Why maxPoolSize Exists

Most blocking operations unmount a virtual thread and free its carrier, so the carrier count never needs to change. But some operations capture the carrier: the virtual thread blocks while still mounted, because the JDK cannot park it there. Examples include some file system operations, which block in the OS with no readiness mechanism to wait on, and, before JDK 24, Object.wait() inside synchronized.

If four carriers were all captured that way, every other virtual thread would stop. To prevent that, for these operations the scheduler compensates: it temporarily adds an extra carrier while one is captured, so the number of carriers able to run code stays at parallelism. When the blocking operation ends, the extra carrier eventually goes away. maxPoolSize is the limit on how far this can grow.

Notice what compensation does not cover. Pinning while blocking inside synchronized on JDK 21 does not trigger compensation, so a few long pinned waits can still block every carrier. That is a pinning problem, fixed by JDK 24 or by changing the code, not by raising maxPoolSize.

Step throughWhat the scheduler does when a virtual thread blocks
  1. Virtual thread blockssocket read, sleep, lock, file read ...
  2. Can it unmount?adapted operation, not pinned
    YesPark it; carrier runs the next taskNoContinue
  3. Does this operation compensate?some file I/O; Object.wait before JDK 24
    YesAdd a carrier, up to maxPoolSizeNoCarrier is held until the wait ends

3 steps in order. Play them, or step through them one at a time.

4When Changing the Settings Makes Sense

Changing parallelism rarely helps throughput. Raising it above the number of cores does not create more CPU; four cores still execute at most four threads at once, and more carriers only add context switching. Lowering it below the core count limits how much CPU virtual threads can use.

There are a few legitimate reasons. The JVM may see more processors than the service should use, for example on a large host without container CPU limits shared with other processes; setting parallelism, or better the JVM's -XX:ActiveProcessorCount, keeps virtual threads from competing too aggressively. In tests, setting parallelism=1 makes scheduling more deterministic and can expose concurrency bugs or pinning faster. And as a temporary measure on JDK 21, a slightly higher parallelism can soften stalls caused by pinning until the real fix lands, at the cost of more context switches. Raising maxPoolSize helps only when compensation is hitting the cap, for example with heavy file I/O on virtual threads, which a thread dump or the scheduler's metrics would show.

In every other case, the better question is not how many carriers we have but what is holding them, which JFR's jdk.VirtualThreadPinned events and a jcmd thread dump answer.

5Can We Plug In a Custom Scheduler?

Not with a supported API. As of Java 25, Thread.Builder.OfVirtual has no method to supply a scheduler, and every virtual thread uses the JDK's default one. The JDK has an internal mechanism, and the idea of custom schedulers has been discussed for future releases, but code that reaches for it through reflection or internal properties is relying on unsupported behaviour that may change in any update. If a workload needs different scheduling, such as strict priorities, the supported options are to use platform threads with a dedicated executor for that work, or to control concurrency with semaphores and queues in front of the virtual threads.

6Follow-up questions

Why is the pool FIFO rather than LIFO?

ForkJoinPool's default local order suits recursive divide-and-conquer tasks, where the most recent subtask is best run first. Virtual threads are independent tasks, such as requests, so first-in first-out keeps waiting times fair and avoids starving older threads.

Is it a problem that parallel streams and virtual threads both use ForkJoinPool?

They use different pool instances, so they do not share carriers. Heavy parallel stream work still competes for the same CPU cores, though, so CPU-bound parallel work inside a virtual-thread server reduces the CPU available to request handling.

How can we see the scheduler's state in production?

A jcmd thread dump shows carriers and what they run, and JFR shows pinning and submit failures. Recent JDKs also expose a management bean with the scheduler's parallelism, pool size and counts of mounted and queued virtual threads; check your version for its availability.

7Conclusion

In this answer, we saw that the default virtual thread scheduler is a FIFO ForkJoinPool whose parallelism defaults to the number of available processors. jdk.virtualThreadScheduler.parallelism sets how many carriers normally run, and jdk.virtualThreadScheduler.maxPoolSize caps the extra carriers added to compensate when some operations capture a carrier. Changing them rarely helps, because CPU-bound work is limited by cores and pinning needs its own fix, and as of Java 25 there is no supported public API for a custom scheduler.

What to say in the interviewAbout 80 seconds aloud

Open with

The default scheduler is a dedicated ForkJoinPool running in FIFO mode, separate from the common pool that parallel streams use. Its parallelism, the number of carriers it normally keeps running, defaults to availableProcessors, so in a container with a 4-CPU limit you get 4 carriers.

Then, if they want more

You can change it only at startup with system properties: jdk.virtualThreadScheduler.parallelism sets that number, and jdk.virtualThreadScheduler.maxPoolSize caps the total, which by default is the larger of parallelism and 256.

The reason maxPoolSize exists is compensation: some operations capture the carrier instead of unmounting, like certain file I/O, and for those the pool temporarily adds a carrier so the others keep running. It doesn't cover pinning in synchronized on JDK 21, which is why that can stall everything. In practice I'd rarely change these.

More carriers than cores doesn't give you more CPU, just more context switching. The cases where I would are limiting CPU use on a shared host, setting parallelism to 1 in tests to make scheduling deterministic, or as a short-term mitigation for pinning on 21.

Usually the right question is what's holding the carriers, which JFR pinned events and a jcmd thread dump answer. And as of Java 25 there's no supported public API for plugging in a custom scheduler.

About this answer

Last updated
12 November 2026
Versions it names
Java 25, Java 21, Java 24
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
JEP 444, Virtual Threads
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 is the virtual thread scheduler configured, and when would you change it?": https://scrivio-interview-library.netlify.app/java/virtual-threads/f2d41e27ef/