A shutdown task can still succeed ?
Ron Pressler
ron.pressler at oracle.com
Tue Feb 8 15:33:52 UTC 2022
What is the cause of the surprise? The name “shutdown”?
Shutdown doesn’t mean cancel, but “the scope’s computation is done; I have all that I need.” Perhaps a better name is needed. At various times we considered “cancelAll”, “complete” and “bail.” All of them have some positive or negative connotations, while what we want is something neutral — we’re done, either successfully or not. Shutdown seemed neutral enough.
Therefore, a task that calls shutdown signals that it has what it needs to complete the operation, and does not cancel itself. Of course, it can choose to fail by throwing an exception.
— Ron
On 8 Feb 2022, at 14:11, Remi Forax <forax at univ-mlv.fr<mailto:forax at univ-mlv.fr>> wrote:
Hi all,
try (var scope = new StructuredTaskScope<>()) {
var future1 = scope.fork(() -> {
Thread.sleep(1_000);
return "task1";
});
var future2 = scope.fork(() -> {
Thread.sleep(50);
scope.shutdown(); // explicit shutdown`
return "task2";
});
scope.join();
System.out.println("state1 " + future1.state());
System.out.println("state2 " + future2.state());
}
prints
state1 FAILED
state2 SUCCESS
which is surprising !
regards,
Rémi
More information about the loom-dev
mailing list