Q66: What are Virtual Threads (Project Loom - Java 21) and how do they differ from Platform Threads?

  • Platform Threads: $1 o 1$ mapping to OS native threads. Heavy memory stack footprint (~1MB), expensive context switching. Limited to thousands of threads.
  • Virtual Threads: Lightweight JVM-managed threads ($M o N$ mapping onto a small pool of Platform Carrier Threads). Extremely low memory footprint (~few KB). Allows scaling applications to millions of concurrent threads.
Virtual Threads vs Platform OS Threads Architecture
Key Takeaways
  • Virtual Threads enable millions of concurrent threads with minimal memory overhead.
  • Mounted dynamically onto OS Carrier Threads by the JVM during execution.
Knowledge Check

What primary problem do Virtual Threads solve in high-throughput enterprise applications?