- Loading...
...
| Code Block | ||
|---|---|---|
| ||
ThreadFactory factory = Thread.builder().virtual().name("worker", 0).factory(); |
The following creates an ExecutorService that runs each task in its own virtual thread. The example uses the try-with-resources construct to ensure that the ExecutorService is shutdown and that the two tasks (each run in its own virtual thread) complete before continuing.
...