throw interrupted exception instead of catching and doing nothing

This commit is contained in:
Luca Conte 2025-05-07 22:29:51 +02:00
parent be6972b898
commit d6eabf0b48
1 changed files with 3 additions and 7 deletions

View File

@ -47,18 +47,14 @@ public class SimpleExecutorCompletionService_with_take<ResultType> {
}
}
synchronized public Future<ResultType> take() {
synchronized public Future<ResultType> take() throws InterruptedException {
// update list first to check if tasks are already completed
this.updateFuturesLists();
// wait until a task finishes, if there aren't any currently done
while (this.doneFutures.isEmpty()) {
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
wait();
// update list again, after being notified, since callable wrapper can't update list
// this SHOULD always result in at least one future being added to the done list
this.updateFuturesLists();