- Loading...
...
The following use a static factory method to create a virtual thread, invokes its start method to schedule it, and then invokes the join method to wait up to 5 seconds for the thread to terminate.
| Code Block | ||
|---|---|---|
| ||
var thread = Thread.newThread(Thread.VIRTUAL, () -> System.out.println("hello")); // unstarted
thread.start();
thread.join(Duration.ofSeconds(5)); |
...