This is the CSR for JEP 425: Virtual Threads (Preview) (JDK-8277131).
Summary
Introduce virtual threads to the Java Platform. Virtual threads are lightweight threads that dramatically reduce the effort of writing, maintaining, and observing high-throughput concurrent applications.
Problem
The goal of the JEP is to enable server applications written in the simple thread-per-request style to scale. Unfortunately, the number of threads is limited because the JDK implements java.lang.Thread
as a thin wrapper over operating system threads. The Motivation section of the JEP provides a lot of discussion on this topic and how some developers workaround the limitation by giving up on the thread-per-request style in favor of thread-sharing and the asynchronous style.
Solution
Introduce a lightweight implementation of threads that are provided by the JDK rather than the OS. This allows developers to write clear code in the thread-per-request style. The JEP provides lengthy discussion of the proposed solution.
Specification
The specdiffs for the Java APIs, JNI spec, JVM TI spec, and JDWP spec are attached.
The Java API changes proposed include both SE and JDK-specific APIs. A number of APIs are proposed as preview APIs, a number of APIs are proposed as permanent APIs, one method in j.l.Thread is deprecated, and several terminally deprecated in j.l.ThreadGroup are degraded. No APIs are removed.
The Java APIs include new methods on j.u.concurrent.ForkJoinPool
and j.u.concurrent.ForkJoinTask
. Prof. Doug Lea is working on a PR and CSR proposing to add these methods in Java 19, in which case they will drop-off the list of API changes here.
The other interface changes in the JEP are JDK-specific:
New system properties. The system properties for configuration/tuning are documented in an implNote in the Thread class description
- jdk.virtualThreadScheduler.parallelism (for tuning)
- jdk.virtualThreadScheduler.maxPoolSize (for tuning)
- jdk.tracePinnedThreads (for diagnostics)
New jdb command line option, documented in usage printed by
jdb -help
- -trackvthreads track virtual threads as they are created
New JDWP agent option, documented in usage printed by
-agentlib:jdwp=help
- enumeratevthreads=y|n thread lists include all vthreads, defaults to n
New jcmd command, documented in usage printed by
jcmd <pid> help Thread.dump_to_file
- jcmd Thread.dump_to_file [-format=json] [-overwrite] file
New thread dump in JSON format, intended for tools to parse.
New JFR events:
- jdk.VirtualThreadStart
- jdk.VirtualThreadEnd
- jdk.VirualThreadPinned
- jdk.VirtualThreadSubmitFailed
- csr of
-
JDK-8284161 Implementation of Virtual Threads (Preview)
- Resolved
- relates to
-
JDK-8304920 Implementation of Virtual Threads
- Closed
-
JDK-8296673 Implementation of Virtual Threads (Second Preview)
- Closed