Java 21 Virtual Thread Carrier Pinning Inside `synchronized` Block
Blocking I/O inside a `synchronized` monitor pins the underlying platform carrier thread.
Runs locally in browser
Free · No login
Independently Verified 2026-11-25
v4.1.0
Identifier: Java 21 Virtual Thread Carrier Pinning Inside `synchronized` Block
Platform: Java
Common Root Causes:
- Blocking I/O inside a `synchronized` monitor pins the underlying platform carrier thread.
Interactive Diagnostic Checklist
Verified Solutions:
- Replace `synchronized` around blocking I/O with `ReentrantLock` or upgrade to Java 24 (JEP 491).
Safe Diagnostic Command:
Run with -Djdk.tracePinnedThreads=full
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.
Technical Explanation
Blocking I/O inside a `synchronized` monitor pins the underlying platform carrier thread. Recommended diagnostic: `Run with -Djdk.tracePinnedThreads=full`. Remediation: Replace `synchronized` around blocking I/O with `ReentrantLock` or upgrade to Java 24 (JEP 491).
Worked Examples
- Run `Run with -Djdk.tracePinnedThreads=full` to verify root cause before applying the remediation.
Limitations & Assumptions
- Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.
Source References & Verification
Resource ID: err-java-virtual-thread-pinning · Independently verified: 2026-11-25