Java / Java 21 Virtual Threads Interview questions
What is the purpose of Thread.ofVirtual()?
Thread.ofVirtual() is the entry point for creating and configuring virtual threads. It returns a Thread.Builder.OfVirtual instance rather than a thread itself.
From that builder you can chain a name pattern, an uncaught exception handler, and finally call .start(runnable) to launch the thread or .unstarted(runnable) to build it without starting it yet.
It exists specifically so virtual thread creation and configuration follow the same fluent pattern as platform threads, keeping the two thread kinds symmetrical in the API.
More Related questions...