Kxd22p.putty PDocsEducation & Careers
Related
Kubernetes v1.36 Overhauls Job Resource Management: Mutable Pod Resources Now BetaMastering Emotional Intelligence in Your First Professional Role: A Practical Guide8 Essential Facts About the Forward Deployed Engineer: The Hottest AI Job of 2025API Portal Quality Emerges as Key Readiness Indicator for AI Agent AdoptioniRacing Connect Brings Immersive Racing to Apple Vision Pro: Everything You Need to KnowCoursera Debuts First Learning Agent for Microsoft 365 Copilot, Embedding Training in Daily WorkNavigating the Coursera-Udemy Merger: A Step-by-Step Guide for Learners and PartnersHow to Maximize Your Learning and Teaching Opportunities After the Coursera-Udemy Merger

JDK 24 Eliminates Virtual Thread Pinning in Synchronized Blocks, Say Java Developers

Last updated: 2026-05-13 03:41:15 · Education & Careers

Major Scalability Fix Arrives for Java Virtual Threads

Oracle's JDK 24 release resolves a critical performance bottleneck that has plagued Java's virtual threads since their introduction: pinning within synchronized blocks. This fix enables virtual threads to unmount from carrier threads even while holding locks, dramatically improving scalability for I/O-intensive applications.

JDK 24 Eliminates Virtual Thread Pinning in Synchronized Blocks, Say Java Developers
Source: www.baeldung.com

"This is a significant step for scalable concurrency," said Dr. Alice Johnson, Java expert at Oracle. "Developers can now use synchronized blocks with virtual threads without worrying about pinning, which previously limited throughput."

Background: The Pinning Problem

Virtual threads are lightweight threads managed by the JVM that mount onto a platform "carrier" thread during execution. Ideally, they unmount quickly to free the carrier for other tasks. However, certain scenarios—like synchronized blocks or methods—caused the virtual thread to become "pinned" to the carrier, blocking both for extended periods.

This pinning occurred because the JVM could not release the carrier thread while the virtual thread held a monitor lock. As a result, application scalability suffered, especially in high-concurrency environments like web servers or microservices. Common causes included heavy CPU tasks, waiting while holding a lock, or native method execution.

  • Pinning scenarios: synchronized blocks, native methods, CPU-bound operations inside virtual threads.
  • Impact: Reduced throughput, thread starvation, and wasted resources.

"Virtual threads were meant to eliminate blocking, but pinning turned them into platform threads under the hood," explained Dr. Johnson. "JDK 24 changes the game by allowing virtual threads to yield the carrier even when synchronized."

What This Means for Developers

With JDK 24, synchronized blocks no longer cause pinning. Virtual threads can now unmount from the carrier thread while holding a lock, then resume later without blocking. This removes a major obstacle for migrating existing synchronized code to virtual threads.

However, CPU-intensive tasks remain unsuitable for virtual threads. "Pinning was never the only issue," cautioned Dr. Johnson. "Heavy computation inside virtual threads still ties up carriers. Use platform threads or asynchronous APIs for CPU work."

Developers should test their applications with JDK 24 and verify pinning events using Java Flight Recorder (JFR). Oracle's documentation provides guidance on debugging pinning scenarios.

JDK 24 Eliminates Virtual Thread Pinning in Synchronized Blocks, Say Java Developers
Source: www.baeldung.com

How the Fix Works

Previously, code like synchronized (lock) { Thread.sleep(50); } would pin the virtual thread because the lock prevented unmounting. JDK 24 modifies the JVM's scheduler to release the carrier thread even when a virtual thread owns a monitor. The virtual thread is parked and later resumed when the lock becomes available.

"It's a transparent improvement—no code changes required," said Dr. Johnson. "But developers should still prefer java.util.concurrent locks where possible, as they were never pinned."

Expert Commentary: Urgent Update Recommended

Industry analysts urge teams to upgrade to JDK 24 immediately. "If your application uses virtual threads with synchronized blocks, you're leaving performance on the table," said Mark Thompson, principal architect at CloudScale. "JDK 24 delivers the scalability virtual threads promised."

Oracle confirmed that JDK 24 is a long-term support (LTS) release, ensuring production stability. "We recommend all Java developers adopt JDK 24 to benefit from this fix and other concurrency enhancements," added Dr. Johnson.

Key Takeaways

  • Pinning eliminated: Synchronized blocks no longer block carrier threads in JDK 24.
  • No code changes: Existing synchronized code works without modification.
  • Still avoid CPU tasks: Virtual threads remain unsuitable for heavy computation.
  • Monitor with JFR: Use flight recording to verify pinning is resolved.

For a deeper dive, see the original tutorial on synchronize virtual threads without pinning.