Java / Java 21 Virtual Threads Interview questions
Why do virtual thread priorities have little practical effect?
Calling setPriority() on a virtual thread is effectively a no-op, and getPriority() always reports Thread.NORM_PRIORITY, regardless of what you set.
Thread priority historically was a hint passed down to the OS scheduler, which decides how to time-slice platform threads. Virtual threads aren't scheduled by the OS at all - they're scheduled cooperatively by the JVM's own ForkJoinPool-based scheduler, which doesn't currently use priority as an input.
So priority-based tuning that worked for platform thread pools simply doesn't translate to virtual threads; concurrency and fairness there are managed differently, largely through how and when carrier threads become available.
More Related questions...