Versions Compared

Key

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

...

The Thread.Builder API can also be used to create virtual threads that are configured at build timeThe first snippet below creates an un-started thread. The second example creates second snippet creates and starts a thread with thread name "bob".

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

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

...