Lab 7 · Virtual Threads Basics

Difficulty: Advanced Time: 45 minutes Topics: Virtual thread creation, performance, characteristics

Requires: Java 21+


Objectives

  • ✅ Create virtual threads with ofVirtual()
  • ✅ Run millions of virtual threads
  • ✅ Compare performance with platform threads for I/O
  • ✅ Understand mount/unmount behavior

Key Exercises

Exercise 1: Create named virtual threads Exercise 2: Run 100,000 virtual threads Exercise 3: Benchmark I/O-bound work (virtual vs platform) Exercise 4: CPU-bound work comparison (virtual vs platform)


References