Java / Java 21 Virtual Threads Interview questions
How do you configure the number of carrier threads used?
Two system properties control the virtual thread scheduler's carrier pool: jdk.virtualThreadScheduler.parallelism sets the baseline pool size (default is the core count), and jdk.virtualThreadScheduler.maxPoolSize sets an upper bound the JVM can grow to temporarily.
java -Djdk.virtualThreadScheduler.parallelism=8 \ -Djdk.virtualThreadScheduler.maxPoolSize=16 \ -jar myapp.jar
The maxPoolSize setting acts as a safety valve: when many virtual threads pin simultaneously, the scheduler can spin up extra carrier threads beyond the base parallelism so pinned work doesn't starve the whole application, though it doesn't remove the pinning itself.
More Related questions...