Virtual Threads vs Platform Threads

Comparison

Platform threadVirtual thread
Managed byOSJVM
Memory~1 MB stack reservedsmall, grows on the heap
Creation costexpensive (system call)cheap (object allocation)
How manythousandsmillions
Pool them?yes (thread pools)no — create one per task
Best forCPU-bound workI/O-bound, blocking code
Daemonconfigurablealways daemon
ThreadLocalfineworks, but millions of copies can use a lot of memory

Virtual Threads vs Reactive

Before Loom, high-concurrency Java used reactive libraries (WebFlux, RxJava): non-blocking but hard to read and debug. Virtual threads give similar scalability with plain, blocking, step-by-step code and normal stack traces.

// Reactive (WebFlux)
return userRepo.findById(id)
        .flatMap(user -> orderClient.ordersFor(user.id())
                .map(orders -> new Profile(user, orders)));

// Virtual threads: same scalability, ordinary code
User user = userRepo.findById(id).orElseThrow();
List<Order> orders = orderClient.ordersFor(user.id());
return new Profile(user, orders);