From bd1f50c5020e34534ed7c8c228a137fed2257e88 Mon Sep 17 00:00:00 2001 From: Vankka Date: Fri, 7 Jun 2024 17:07:15 +0300 Subject: [PATCH] Don't run dependency download on a separate thread on bukkit --- .../bukkit/DiscordSRVBukkitBootstrap.java | 3 ++- .../bungee/DiscordSRVBungeeBootstrap.java | 3 ++- .../common/bootstrap/LifecycleManager.java | 15 +++++++++------ .../velocity/DiscordSRVVelocityBootstrap.java | 3 ++- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/DiscordSRVBukkitBootstrap.java b/bukkit/src/main/java/com/discordsrv/bukkit/DiscordSRVBukkitBootstrap.java index 587835db..807ebb50 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/DiscordSRVBukkitBootstrap.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/DiscordSRVBukkitBootstrap.java @@ -47,7 +47,8 @@ public class DiscordSRVBukkitBootstrap extends BukkitBootstrap implements IBoots logger, plugin.getDataFolder().toPath(), getDependencyResources(), - getClasspathAppender() + getClasspathAppender(), + false ); } diff --git a/bungee/src/main/java/com/discordsrv/bungee/DiscordSRVBungeeBootstrap.java b/bungee/src/main/java/com/discordsrv/bungee/DiscordSRVBungeeBootstrap.java index 3f73a5bc..383bb307 100644 --- a/bungee/src/main/java/com/discordsrv/bungee/DiscordSRVBungeeBootstrap.java +++ b/bungee/src/main/java/com/discordsrv/bungee/DiscordSRVBungeeBootstrap.java @@ -44,7 +44,8 @@ public class DiscordSRVBungeeBootstrap extends BungeeBootstrap implements IBoots logger, plugin.getDataFolder().toPath(), new String[] {"dependencies/runtimeDownload-bungee.txt"}, - getClasspathAppender() + getClasspathAppender(), + true ); } diff --git a/common/src/main/java/com/discordsrv/common/bootstrap/LifecycleManager.java b/common/src/main/java/com/discordsrv/common/bootstrap/LifecycleManager.java index 74e70b26..4a606d72 100644 --- a/common/src/main/java/com/discordsrv/common/bootstrap/LifecycleManager.java +++ b/common/src/main/java/com/discordsrv/common/bootstrap/LifecycleManager.java @@ -41,16 +41,17 @@ public class LifecycleManager { private final Logger logger; private final ExecutorService taskPool; private final DependencyLoader dependencyLoader; - private final CompletableFuture completableFuture; + private CompletableFuture completableFuture; public LifecycleManager( Logger logger, Path dataDirectory, String[] dependencyResources, - ClasspathAppender classpathAppender + ClasspathAppender classpathAppender, + boolean useExecutor ) throws IOException { this.logger = logger; - this.taskPool = Executors.newSingleThreadExecutor(runnable -> new Thread(runnable, "DiscordSRV Initialization")); + this.taskPool = useExecutor ? Executors.newSingleThreadExecutor(runnable -> new Thread(runnable, "DiscordSRV Initialization")) : null; List resourcePaths = new ArrayList<>(Collections.singletonList( "dependencies/runtimeDownload-common.txt" @@ -63,9 +64,6 @@ public class LifecycleManager { classpathAppender, resourcePaths.toArray(new String[0]) ); - - this.completableFuture = dependencyLoader.download(); - completableFuture.whenComplete((v, t) -> taskPool.shutdown()); } public void loadAndEnable(Supplier discordSRVSupplier) { @@ -76,6 +74,11 @@ public class LifecycleManager { private boolean load() { try { + this.completableFuture = dependencyLoader.download(); + if (taskPool != null) { + completableFuture.whenComplete((v, t) -> taskPool.shutdown()); + } + completableFuture.get(); return true; } catch (InterruptedException ignored) { diff --git a/velocity/src/main/java/com/discordsrv/velocity/DiscordSRVVelocityBootstrap.java b/velocity/src/main/java/com/discordsrv/velocity/DiscordSRVVelocityBootstrap.java index 33bcc3a0..6498d600 100644 --- a/velocity/src/main/java/com/discordsrv/velocity/DiscordSRVVelocityBootstrap.java +++ b/velocity/src/main/java/com/discordsrv/velocity/DiscordSRVVelocityBootstrap.java @@ -64,7 +64,8 @@ public class DiscordSRVVelocityBootstrap implements IBootstrap { this.logger, dataDirectory, new String[] {"dependencies/runtimeDownload-velocity.txt"}, - classpathAppender + classpathAppender, + true ); this.proxyServer = proxyServer; this.pluginContainer = pluginContainer;