Java / Java 21 Virtual Threads Interview questions
How does virtual thread stack size differ from a platform thread's?
A platform thread reserves a fixed native stack up front, commonly around 1MB depending on the OS and JVM flags, whether or not the thread ever needs that much space.
A virtual thread's stack instead starts very small and lives on the heap as part of its continuation object, growing and shrinking dynamically as the call depth changes during execution.
This is precisely why the JVM can support millions of virtual threads at once: reserving a full native stack per thread at that scale would exhaust memory almost immediately, while a small, elastic, garbage-collected stack scales far more gracefully.
More Related questions...