- Loading...
...
| Code Block | ||
|---|---|---|
| ||
ThreadFactory factory = Thread.builder().virtual().name("worker", 0).factory(); |
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.
...