- Loading...
...
Thread factory = Thread.builder().virtual().factory()try (ExecutorService executor = Executors.newUnboundedExecutor(factory)) {executor.schedulesubmit(task1);executor.schedulesubmit(task2);}
A thread executing this code will block in the executor’s close method until the two tasks have have completed and executor has terminated.
...
An ExecutorService can be wrapped with a deadline so that its shutdowNow method is invoked if the deadline expires before the executor has terminated.
ThreadThreadFactory factory = Thread.builder().virtual().factory()var deadline = Instant.now().plusSeconds(102);try (ExecutorService executor = Executors.newUnboundedExector(factory).withDeadline(deadline, null)) {
executor.schedulesubmit(task1);executor.schedulesubmit(task2);}
Deadlines do not correctly also work with nested usages . In the original FiberScope prototype, the scope had a owner that would be interrupted when the deadline expired. We may explored something similar here.by specifying the current thread as the owner. The owner is interrupted when the deadline expires.
ThreadFactory factory = Thread.builder().virtual().factory();
var deadline = Instant.now().plusSeconds(1);
try (ExecutorService executor1 = Executors.newUnboundedExecutor(factory)
.withDeadline(deadline, Thread.currentThread())) {
try (ExecutorService executor2 = Executors.newUnboundedExecutor(factory)) {
executor2.submit(task1);
executor2.submit(task2);
}
}