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