Virtual threads — managed by JVM. Platform threads — managed by OS.
Platform threads:
1Thread pt = new Thread(() -> { });2// Platform thread by default34Thread ptDaemon = new Thread(() -> { });5ptDaemon.setDaemon(true);6// Daemon platform thread
Virtual threads:
1Thread vt = Thread.ofVirtual().start(() -> { });2// Virtual thread34// Naming virtual threads5Thread vtNamed = Thread.ofVirtual()6 .name("worker-", 0)7 .start(() -> { });
Key differences:
Thread.join(), virtual threads use Thread.join() too but may behave differently with structured concurrency.System design context:
Common pitfalls:
synchronized blocks can pin virtual threads to carrier threads.Production configuration:
1// Configure carrier thread pool size2System.setProperty("jdk.virtualThreadScheduler.parallelism", "1");3System.setProperty("jdk.virtualThreadScheduler.maxPoolSize", "1");
Monitoring/observability:
jcmd Thread.dump_to_file -format=json for virtual thread dumps.