Skip to content

Commit

Permalink
Fix waiting for last task in ViewManager close.
Browse files Browse the repository at this point in the history
Prefer attempting to cancel task before execution before waiting.
Also removes double logging of execution exception, and avoids problem where get cannot be called after cancel.
  • Loading branch information
timw authored and pkendall64 committed Oct 31, 2022
1 parent cdcec5b commit 3c53320
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,20 @@ public void close() {
}
if (lastTask != null) {
try {
try {
// Try to cancel last task before it runs, otherwise wait for completion
if (!lastTask.cancel(false)) {
lastTask.get(20, TimeUnit.SECONDS);
} catch (TimeoutException e) {
lastTask.cancel(true);
lastTask.get();
}

} catch (TimeoutException e) {
OLogManager.instance()
.warn(
this,
"Timeout waiting for last task to complete view update background operations");
} catch (InterruptedException e) {
throw OException.wrapException(
new OInterruptedException("Terminated while waiting update view to finis"), e);
} catch (ExecutionException e) {
OLogManager.instance().warn(this, "Issue terminating view update background operations", e);
// Will already have been logged by thread pool executor
}
}

Expand Down

0 comments on commit 3c53320

Please sign in to comment.