Oracle’s Java team is addressing issues where virtual threads may block and prevent native threads from being released
Java’s introduction of virtual threads in JDK 21 aimed to simplify the development of concurrent applications, but it has encountered a notable issue known as “pinning.” This problem, identified in a recent blog post on the Inside Java website, affects performance and scalability, potentially leading to starvation and deadlock in some cases.
The pinning issue primarily arises in scenarios involving synchronized methods or statements. Specifically, it occurs when a virtual thread is parked while waiting to enter a synchronized method or when it is blocked because the monitor of the synchronized object is held by another thread. In these situations, the native thread associated with the virtual thread remains occupied and is not released for other tasks.
Oracle’s Project Loom team, responsible for developing JVM features to support lightweight concurrency, has addressed this issue in recent early access builds. These updates modify the object monitor implementation to prevent pinning in the identified scenarios. The changes aim to ensure that native threads are available for other work and to enhance the overall efficiency of virtual threads.
Developers are encouraged to test the new builds with code and libraries that rely heavily on synchronization to evaluate the improvements. Feedback can be provided through the Loom mailing list, helping the team to refine the implementation further.
Despite the challenges, Oracle reports that virtual threads have been positively received by the Java community. Project Loom, previewed in JDK 19 and JDK 20, has been praised for its ability to ease the development and maintenance of high-throughput concurrent applications. The ongoing updates and community engagement are expected to address the pinning issue effectively and enhance the benefits of virtual threads in future releases.