Java’s virtual threads, introduced in JDK 21 in September 2023 to make it easier to write and maintain concurrent applications, has suffered from a “pinning” issue that arises with synchronized methods or synchronized statements.
Oracle detailed the virtual thread pinning issue this week on the Inside Java website. The two most common cases involve a virtual thread parking while in a synchronized method, and a virtual thread blocking when entering a synchronized method, because the object’s associated monitor is held by another thread. In both cases, the carrier or native thread is not released to do other other work. Virtual thread pinning could impact performance and scalability and potentially result in starvation and deadlock, according to the blog post.
New early access builds for Java’s Project Loom introduce changes to the object monitor implementation that do not pin in these two common cases. The Loom team is seeking help from users to test the reliability and performance of these updated object monitors with code that uses virtual threads and with libraries that are heavily synchronized. To report an issue, developers should use the Loom mailing list.
Project Loom is the OpenJDK project that develops JVM features and APIs to support lightweight concurrency. Previewed in JDK 19 and JDK 20, virtual threads are lightweight threads that dramatically reduce the effort of writing, maintaining, and observing high-throughput concurrent applications, according to Oracle. Despite the pinning issue, Oracle said virtual threads have been extremely well-received by the Java community and ecosystem.