79119162

Date: 2024-10-23 18:14:03
Score: 1
Natty:
Report link

You can tryout the ExtendedFuture class of the futures4j library which extends CompletableFuture and supports thread interruption of stages through ExtendedFuture#cancel(true). See https://github.com/futures4j/futures4j#ExtendedFuture

var myFuture = ExtendedFuture.supplyAsync(...);

myFuture.cancel(true); // Will attempt to interrupt the async task

var myFutureNonInterruptible = myFuture.asNonInterruptible();
myFutureNonInterruptible.cancel(true); // Behaves like CompletableFuture.cancel(true), which ignores the boolean value
Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Seb T