[Smell] Improper InterruptedException handling

- Fixes thread interruption if interrupted during WebServer shutdown
- Fixes thread interruption if interrupted during Processing shutdown
This commit is contained in:
Rsl1122 2018-11-11 20:17:50 +02:00
parent c513e08728
commit 6b3d07dac1
2 changed files with 15 additions and 9 deletions

View File

@ -145,16 +145,19 @@ public class Processing implements SubSystem {
errorHandler.log(L.WARN, this.getClass(), e); errorHandler.log(L.WARN, this.getClass(), e);
} }
} }
if (!nonCriticalExecutor.isTerminated()) {
try { try {
nonCriticalExecutor.awaitTermination(1, TimeUnit.SECONDS); if (!nonCriticalExecutor.isTerminated() && !nonCriticalExecutor.awaitTermination(1, TimeUnit.SECONDS)) {
} catch (InterruptedException e) {
nonCriticalExecutor.shutdownNow(); nonCriticalExecutor.shutdownNow();
} }
}
if (!criticalExecutor.isTerminated()) { if (!criticalExecutor.isTerminated()) {
criticalExecutor.shutdownNow(); criticalExecutor.shutdownNow();
} }
} catch (InterruptedException e) {
logger.error("Processing shutdown thread interrupted: " + e.getMessage());
nonCriticalExecutor.shutdownNow();
criticalExecutor.shutdownNow();
Thread.currentThread().interrupt();
}
logger.info(locale.get().getString(PluginLang.DISABLED_PROCESSING_COMPLETE)); logger.info(locale.get().getString(PluginLang.DISABLED_PROCESSING_COMPLETE));
} }
} }

View File

@ -258,10 +258,13 @@ public class WebServer implements SubSystem {
ExecutorService service = (ExecutorService) executor; ExecutorService service = (ExecutorService) executor;
service.shutdown(); service.shutdown();
try { try {
service.awaitTermination(5, TimeUnit.SECONDS); if (!service.awaitTermination(5, TimeUnit.SECONDS)) {
} catch (InterruptedException timeoutExceededEx) {
service.shutdownNow(); service.shutdownNow();
} }
} catch (InterruptedException e) {
logger.error("WebServer ExecutorService shutdown thread interrupted on disable: " + e.getMessage());
Thread.currentThread().interrupt();
}
} }
} }