From d6eabf0b4882ca029813c4ad9950d23cacfd7f90 Mon Sep 17 00:00:00 2001 From: Luca Conte Date: Wed, 7 May 2025 22:29:51 +0200 Subject: [PATCH] throw interrupted exception instead of catching and doing nothing --- u07-2/SimpleExecutorCompletionService_with_take.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/u07-2/SimpleExecutorCompletionService_with_take.java b/u07-2/SimpleExecutorCompletionService_with_take.java index b355c13..4486e87 100644 --- a/u07-2/SimpleExecutorCompletionService_with_take.java +++ b/u07-2/SimpleExecutorCompletionService_with_take.java @@ -47,18 +47,14 @@ public class SimpleExecutorCompletionService_with_take { } } - synchronized public Future take() { + synchronized public Future 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();