Versions Compared

Key

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

...

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

Executors/ExecutorService API

The following example uses the Executors API to create an ExecutorService that runs each task in its own virtual thread. The example uses the try-with-resources construct to ensure that the ExecutorService has terminated before continuing. The example demonstrates the use of the  submit methods (these methods do not block), and the invokeAll/invokeAny combinator methods that execute several tasks and wait them to complete.                                               

...