- Loading...
...
An early of prototype of Project Loom had API named FiberScope to support the scheduling of fibers (a precursor to virtual threads) with initial support in this area. There is no explicit support in the current prototype but it is possible to use existing constructs without needing too many new APIs. In particular, ExecutorService has been retrofitted to extend AutoCloseable so that it’s possible to write code like this:
ThreadThreadFactory factory = Thread.builder().virtual().factory()try (ExecutorService executor = Executors.newUnboundedExecutor(factory)) {executor.submit(task1);executor.submit(task2);}
...
Deadlines also work with nested usages by specifying the current thread as the owner. The owner is interrupted when the deadline expires.
...
try (ExecutorService executor1 = Executors.newUnboundedExecutor(factory)
.withDeadline(deadline, Thread.currentThread())) {
try (ExecutorService executor2 = Executors.newUnboundedExecutor(factory)) {
executor2.submit(task1);
executor2.submit(task2);
}
}
...