I have a method name someTask that I have to invoke 100 times and I am using asynchronous coding as below.
for (int i = 0; i < 100; i++) {
futures.add(CompletableFuture.supplyAsync(
() -> { someTask(); },
myexecutor
));
}
If an exception occurs on any thread while executing someTask() I want to interrupt all the current threads and also stop future threads from executing. What is the best way to handle this?
Update:
I am using ThreadPoolTaskExecutor.