Java / Java 21 Virtual Threads Interview questions
When would you choose platform threads over virtual threads?
Platform threads still make sense for CPU-bound work, where the bottleneck is computation rather than waiting - running more threads than you have cores won't speed that up regardless of thread type.
They're also preferable for code that unavoidably relies on heavy synchronized blocks combined with blocking calls, or that spends significant time in native/JNI code, since both scenarios pin virtual threads and erode their advantage anyway.
Long-lived, small-in-number background threads that need fine control over OS-level scheduling or thread priority are another case where a platform thread is the more predictable choice.
More Related questions...