JDK21 Manage Virtual Thread Executor Service

1.3k views Asked by At

I know that

The JVM maintains a pool of platform threads, created and maintained by a dedicated ForkJoinPool. Initially, the number of platform threads equals the number of CPU cores, and it cannot increase more than 256.

but i don't find how to config number of thread for this pool.

1

There are 1 answers

0
Thomas Kläger On BEST ANSWER

It helps to read the official documentation of java.lang.Thread:

Implementation Note:

In the JDK Reference Implementation, the virtual thread scheduler may be configured with the following system properties:

System properties System property Description
jdk.virtualThreadScheduler.parallelism The number of platform threads available for scheduling virtual threads. It defaults to the number of available processors.
jdk.virtualThreadScheduler.maxPoolSize The maximum number of platform threads available to the scheduler. It defaults to 256.

That means that you can change the maximum pool size when starting your application with

java -Djdk.virtualThreadScheduler.maxPoolSize=512 other arguments ...