From dad7821e26d1f31628754e026fe2b4ecc269ad34 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Sat, 16 Sep 2023 19:34:30 -0400 Subject: [PATCH] Give thread pools time to terminate & Save all data before shutting down --- src/main/java/emu/grasscutter/Grasscutter.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/Grasscutter.java b/src/main/java/emu/grasscutter/Grasscutter.java index 0bb6e1be8..95ba466a2 100644 --- a/src/main/java/emu/grasscutter/Grasscutter.java +++ b/src/main/java/emu/grasscutter/Grasscutter.java @@ -191,6 +191,9 @@ public final class Grasscutter { /** Server shutdown event. */ private static void onShutdown() { + // Save all data. + Database.saveAll(); + // Disable all plugins. if (pluginManager != null) pluginManager.disablePlugins(); // Shutdown the game server. @@ -200,14 +203,14 @@ public final class Grasscutter { // Wait for Grasscutter's thread pool to finish. var executor = Grasscutter.getThreadPool(); executor.shutdown(); - if (!executor.awaitTermination(5, TimeUnit.SECONDS)) { + if (!executor.awaitTermination(1, TimeUnit.MINUTES)) { executor.shutdownNow(); } // Wait for database operations to finish. var dbExecutor = DatabaseHelper.getEventExecutor(); dbExecutor.shutdown(); - if (!dbExecutor.awaitTermination(5, TimeUnit.SECONDS)) { + if (!dbExecutor.awaitTermination(2, TimeUnit.MINUTES)) { dbExecutor.shutdownNow(); } } catch (InterruptedException ignored) {