The next phase of Project Loom and Virtual Threads by Alan Bateman

Learn about Project Loom's virtual threads - how they enable scalable apps without complex async code, plus new features in JDK 24 like pinning diagnostics & structured concurrency

Key takeaways
  • Virtual threads are lightweight threads that enable high scalability without complex async programming models - they are “threads without the baggage”

  • Virtual threads are not pooled and should not be - they are created per task, execute it, and terminate. They are very cheap to create

  • The synchronized keyword works with virtual threads, but may cause “pinning” which impacts scalability. JEP 491 will address this in JDK 24

  • Structured concurrency (JEP 428) provides better task management than Futures, ensuring child tasks complete before parent tasks continue

  • New diagnostic capabilities in JDK 24 improve troubleshooting:

    • Enhanced thread dumps showing virtual thread details
    • JFR events for pinning diagnostics
    • Heap dumps now include unmounted virtual thread stacks
  • Virtual threads don’t make code run faster - they provide scalability benefits by allowing more concurrent operations with simple blocking code

  • The focus is on enabling simple synchronous blocking code rather than complex async programming models

  • Virtual threads are mounted on carrier threads (platform threads) and unmount when blocking to free the carrier for other work

  • Structured concurrency preserves parent-child relationships between tasks and handles cancellation/cleanup automatically

  • Common misconceptions:

    • Virtual threads are not faster than platform threads
    • No need to replace all synchronized code
    • Not meant for thread pooling