Versions Compared

Key

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

...

Code Block
languagejava
Thread thread1 = Thread.builderofVirtual().virtual().taskunstarted(() -> System.out.println("Hello")).build();

Thread thread2 = Thread.builderofVirtual()
                       .virtual()
                       .name("bob")
                       .task.start(() -> System.out.println("I'm Bob!"))
                       .start();


The Thread.Builder API can also be used to create a ThreadFactory. The ThreadFactory created by the following snippet will create virtual threads named "worker-0", "worker-1", "worker-2", ...

Code Block
languagejava
ThreadFactory factory = Thread.builder().virtualofVirtual().name("worker", 0).factory();

...