Pitfalls: Pinning and ThreadLocals
Avoid blocking carrier threads.
Things That Can Go Wrong
Virtual threads are powerful, but two pitfalls can quietly undermine their scalability: pinning and overuse of ThreadLocals.
This lesson explains both and how to avoid them.
What Is Pinning
Pinning happens when a virtual thread cannot unmount from its carrier while blocked. The carrier OS thread stays stuck, defeating the scalability benefit.
When too many carriers are pinned, throughput collapses.
All lessons in this course
- What Are Virtual Threads
- Creating Virtual Threads
- Platform vs Virtual Threads
- Pitfalls: Pinning and ThreadLocals