Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interrupt all running tasks during shutdown #6118

Merged
merged 10 commits into from
Sep 1, 2020
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Fixed

- We fixed an issue where the `.sav` file was not deleted upon exiting JabRef. [#6109](https://github.com/JabRef/jabref/issues/6109)
- We fixed an issue where opening a library from the recent libraries menu was not possible. [#5939](https://github.com/JabRef/jabref/issues/5939)

### Removed
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/jabref/logic/util/DelayTaskThrottler.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public DelayTaskThrottler(int delay) {
this.delay = delay;
this.executor = new ScheduledThreadPoolExecutor(1);
this.executor.setRemoveOnCancelPolicy(true);
this.executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
}

public void schedule(Runnable command) {
Expand All @@ -47,5 +48,19 @@ public void schedule(Runnable command) {

public void shutdown() {
executor.shutdown();
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call above helper method

if (!executor.awaitTermination(60, TimeUnit.SECONDS)) {
LOGGER.debug("One minute passed, saving still not completed. Trying forced shutdown.");
executor.shutdownNow();
if (executor.awaitTermination(60, TimeUnit.SECONDS)) {
LOGGER.debug("One minute passed again - forced shutdown worked.");
} else {
LOGGER.error("DelayedTaskThrottler did not terminate");
}
}
} catch (InterruptedException ie) {
executor.shutdownNow();
Thread.currentThread().interrupt();
}
}
}