Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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
languagejava
var thread = Thread.newThread(Thread.VIRTUAL, () -> System.out.println("hello"));   // unstarted
thread.start();
thread.join(Duration.ofSeconds(5));

...