Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8296673

Implementation of Virtual Threads (Second Preview)

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P4
    • 20
    • core-libs
    • None
    • minimal
    • Hide
      There are no compatibility risks beyond those listed in the CSR for JEP 425.

      The only compatibility issue that has been reported so far is the source compatibility that arises with source code that extends Thread, imports a class named "Builder", and references "Builder" as a simple name in the subclass. This code does not compile with JDK 19 without change. At the time of writing, we've had two bug reports on this issue, both related to code in one of the tests for an Apache "web services" project. The maintainers of this project did a trivial change to ensure that it compiles with older JDK releases and JDK 19. The change was done before the second bug report. The source compatibility issue is detailed in the JDK 19 release note. No action is proposed.
      Show
      There are no compatibility risks beyond those listed in the CSR for JEP 425. The only compatibility issue that has been reported so far is the source compatibility that arises with source code that extends Thread, imports a class named "Builder", and references "Builder" as a simple name in the subclass. This code does not compile with JDK 19 without change. At the time of writing, we've had two bug reports on this issue, both related to code in one of the tests for an Apache "web services" project. The maintainers of this project did a trivial change to ensure that it compiles with older JDK releases and JDK 19. The change was done before the second bug report. The source compatibility issue is detailed in the JDK 19 release note. No action is proposed.
    • Java API
    • SE

    Description

      Summary

      Virtual threads were proposed as a preview feature by JEP 425 and delivered in JDK 19. JEP 436 proposes a second preview to allow time for more feedback and to get more experience with this feature.

      There are no changes since the first preview. JEP 425 (and the corresponding CSR) added a number of APIs as permanent APIs and others as preview APIs. The APIs added as preview APIs are proposed to continue to preview in JDK 20.

      Problem

      The goal of this feature is unchanged, that is the goal is to enable server applications written in the simple thread-per-request style to scale. 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

      The APIs that are proposed to continue preview are:

      interface java.lang.Thread.Builder
      interface java.lang.Thread.Builder.OfPlatform
      interface java.lang.Thread.Builder.OfVirtual
      method java.lang.Thread.ofPlatform()
      method java.lang.Thread.ofVirtual()
      method java.lang.Thread.startVirtualThread()
      method java.lang.Thread.isVirtual()
      method java.util.concurrent.Executors.newThreadPerTaskExecutor(ThreadFactory)
      method java.util.concurrent.Executors.newVirtualThreadPerTaskExecutor()
      method com.sun.jdi.ThreadReference.isVirtual()
      method com.sun.jdi.request.ThreadStartRequest.addPlatformThreadsOnlyFilter()
      method com.sun.jdi.request.ThreadDeathRequest.addPlatformThreadsOnlyFilter()
      enum com.sun.management.HotSpotDiagnosticMXBean.ThreadDumpFormat
      method com.sun.management.HotSpotDiagnosticMXBean.dumpThreads(String, ThreadDumpFormat)
      method jdk.jfr.consumer.RecordedThread.isVirtual()
      JNI function IsVirtualThread
      JVMTI function SuspendAllVirtualThreads
      JVMTI function ResumeAllVirtualThreads
      JVMTI event VirtualThreadStart
      JVMTI event VirtualThreadEnd
      JVMTI capability can_support_virtual_threads
      JDWP command ThreadReference/IsVirtual
      JDWP modifier EventRequest/Set.PlatformThreadsOnly

      In addition, the following APIs specify behavior for virtual threads:

      class java.lang.Thread
      class java.lang.ThreadGroup
      class java.lang.management.ThreadMXBean
      method java.net.Socket.connect(SocketAddress)
      method java.net.Socket.connect(SocketAddress, timeout)
      method java.net.Socket.getInputStream()
      method java.net.Socket.getOutputStream()
      method java.net.ServerSocket.accept()
      method java.net.DatagramSocket.receive(DatagramPacket)
      class com.sun.jdi.VirtualMachine
      class com.sun.jdi.ThreadReference
      class com.sun.jdi.StackFrame
      class com.sun.management.ThreadMXBean
      JVMTI spec sections on Thread, Local Variable, Force Early Return and Timers
      JDWP spec VirtualMachine, ThreadReference and StackFrame command sets

      The following command line options continue for this feature:

      jcmd Thread.dump_to_file [-format=json] [-overwrite] file
      jdb -trackallthreads
      JDWP agent sub option includevirtualthreads=y

      The following system properties continue for this feature:

      jdk.virtualThreadScheduler.parallelism
      jdk.virtualThreadScheduler.maxPoolSize
      jdk.tracePinnedThreads

      The following file formats continue for this feature:

      Thread dump JSON format

      The following Java Flight Recorder events continue for this feature:

      jdk.VirtualThreadStart
      jdk.VirtualThreadEnd
      jdk.VirualThreadPinned
      jdk.VirtualThreadSubmitFailed

      Specification

      There are no specification changes proposed.

      Attachments

        Issue Links

          Activity

            People

              alanb Alan Bateman
              alanb Alan Bateman
              Ron Pressler
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: