Java / Java 21 Virtual Threads Interview questions
What is the difference between virtual threads and platform threads?
The core difference is who does the scheduling and how expensive creation is. Platform threads map 1:1 to OS threads and are scheduled by the operating system; virtual threads are scheduled by the JVM and share a small pool of carrier threads.
| Aspect | Platform Thread | Virtual Thread |
| Mapping to OS thread | 1:1 | Many:few (via carrier threads) |
| Creation cost | Relatively high | Very low |
| Stack storage | Fixed native stack | Small, resizable, on heap |
| Typical count | Hundreds to low thousands | Millions |
Both expose the identical Thread API, so code written for one generally runs unmodified on the other.
More Related questions...