Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-4649

Support Virtual Threads

    • Type: Icon: Epic Epic
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 4.11.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible
    • Needed
    • Hide
      We should mention in What's new that we updated the codebase to avoid unnecessary pinning of virtual threads (https://openjdk.org/jeps/444) and to preserve interrupted status of a thread, as the latter matters for structured concurrency (https://openjdk.org/jeps/453) where it is used for cancellation.
      Show
      We should mention in What's new that we updated the codebase to avoid unnecessary pinning of virtual threads ( https://openjdk.org/jeps/444 ) and to preserve interrupted status of a thread, as the latter matters for structured concurrency ( https://openjdk.org/jeps/453 ) where it is used for cancellation.
    • 4
    • 5
    • 5
    • 100
    • Hide

      Engineer(s): Valentin Kavalenka

      2023-09-29: Updated end date to 2023-10-06

      • Everything is in review. Added a week to the end date for reviews!

       

      2023-09-15: Set target date to 2023-09-29

      • Remaining: 
        • Handle interrupts and replace uninterruptible Lock
      • Valentin has been doing some work for 4.11 release this week leading up to .local and will pick this back up
      • Bumped up Final Cost Est by a week

      2023-09-01: Set target date to 2023-09-08

      • Work is proceeding
      • Remaining: 
        • Fix handling of InterruptedExceptions/SocketExceptions
        • Investigation of ThreadLocalRandom's interaction w/ virtual threads

      2023-08-18: Set target date to 2023-09-01

      • Work started
      • Removal of synchronized blocks and methods in production code in progress
      Show
      Engineer(s): Valentin Kavalenka 2023-09-29: Updated end date to 2023-10-06 Everything is in review. Added a week to the end date for reviews!   2023-09-15: Set target date to 2023-09-29 Remaining:  Handle interrupts and replace uninterruptible Lock Valentin has been doing some work for 4.11 release this week leading up to .local and will pick this back up Bumped up Final Cost Est by a week 2023-09-01: Set target date to 2023-09-08 Work is proceeding Remaining:  Fix handling of InterruptedExceptions/SocketExceptions Investigation of ThreadLocalRandom's interaction w/ virtual threads 2023-08-18: Set target date to 2023-09-01 Work started Removal of synchronized blocks and methods in production code in progress

      Summary

      Virtual threads (https://openjdk.org/jeps/444) support is GA in Java 21 . We should make any necessary improvements to the Java driver to allow our users to make use of these new features.

      Who is the affected end user?

      Any MongoDB Java driver applications using virtual threads in Java 21+.

      How does this affect the end user?

      Users can currently choose to use Future.cancel or ExecutorService.shutdownNow to attempt to cancel or shut down threads. With structured concurrency, any fork (including a transitive fork) can cause threads of all other forks still active to be interrupted. This means that forks should be responsive to interruption.

      How likely is it that this problem or use case will occur?

      As more users upgrade to Java 21, they may need us to handle interruptions differently. 

      If the problem does occur, what are the consequences and how severe are they?

      If a socket operation is interrupted, it will be treated as a a network error. However, it should be treated as an InterruptedException. (JAVA-4646)

      Additionally, it is possible to create a scenario in which all virtual threads are starved of carrier threads due to the fact that all available carrier threads are pinned by synchronized blocks. (JAVA-4642)

      Is this issue urgent?

      Java 21 was released in September 2023. It is an LTS release. While generally users are slow to upgrade production apps to the latest JDK, adoption if newer JDKs is accelerating and we expect users to try this feature out as soon as it's available. Also, many application servers (Helidon, Spring Boot, Weblogic, Quarkus) either already do or will soon be able to operate in a mode where all requests are handled on virtual threads, which means that anyone using those servers with MongoDB will easily be able to create applications which are executing Java driver code on those virtual threads.

      Is this ticket required by a downstream team?

      No 

      Is this ticket only for tests?

      No.

      Cast of Characters

      Engineering Lead: jeff.yemin@mongodb.com
      Product Owner: ashni.mehta@mongodb.com

            Assignee:
            valentin.kovalenko@mongodb.com Valentin Kavalenka
            Reporter:
            ashni.mehta@mongodb.com Ashni Mehta
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              7 weeks, 4 days