From a0029f1df8e440b79c6778d0b3b5ebca22137592 Mon Sep 17 00:00:00 2001 From: Risto Lahtela <24460436+AuroraLS3@users.noreply.github.com> Date: Thu, 25 Mar 2021 08:00:04 +0200 Subject: [PATCH] Made processing shutdown more aggressively Affects issues: - #1814 --- .../plan/processing/Processing.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/processing/Processing.java b/Plan/common/src/main/java/com/djrapitops/plan/processing/Processing.java index a6aa45176..cac480439 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/processing/Processing.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/processing/Processing.java @@ -152,28 +152,35 @@ public class Processing implements SubSystem { } private void shutdownNonCriticalExecutor() { - nonCriticalExecutor.shutdown(); + nonCriticalExecutor.shutdownNow(); } private void shutdownCriticalExecutor() { - List criticalTasks = criticalExecutor.shutdownNow(); - logger.info(locale.get().getString(PluginLang.DISABLED_PROCESSING, criticalTasks.size())); - for (Runnable runnable : criticalTasks) { - if (runnable == null) continue; - try { - runnable.run(); - } catch (Exception | NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) { - errorLogger.warn(e, ErrorContext.builder().build()); + criticalExecutor.shutdown(); + try { + if (!criticalExecutor.awaitTermination(3, TimeUnit.SECONDS)) { + List criticalTasks = criticalExecutor.shutdownNow(); + logger.info(locale.get().getString(PluginLang.DISABLED_PROCESSING, criticalTasks.size())); + for (Runnable runnable : criticalTasks) { + if (runnable == null) continue; + try { + runnable.run(); + } catch (Exception | NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) { + errorLogger.warn(e, ErrorContext.builder().build()); + } + } } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } } private void ensureShutdown() { try { - if (!nonCriticalExecutor.isTerminated() && !nonCriticalExecutor.awaitTermination(1, TimeUnit.SECONDS)) { + if (!nonCriticalExecutor.isTerminated()) { nonCriticalExecutor.shutdownNow(); } - if (!criticalExecutor.isTerminated()) { + if (!criticalExecutor.isTerminated() && !criticalExecutor.awaitTermination(1, TimeUnit.SECONDS)) { criticalExecutor.shutdownNow(); } } catch (InterruptedException e) {