From 656780d027bab2573ffb5f1e6d2b2148efeb90ac Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Wed, 23 Mar 2016 10:22:40 +1100 Subject: [PATCH] Change runAsync in MiniPlugin to use our own thread pool This allows the tasks to run immediately. Using Bukkit's scheduler the async task wont start until the next server tick --- .../Mineplex.Core/src/mineplex/core/MiniPlugin.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/MiniPlugin.java b/Plugins/Mineplex.Core/src/mineplex/core/MiniPlugin.java index 732c13816..dbad6fbdb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/MiniPlugin.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/MiniPlugin.java @@ -1,11 +1,15 @@ package mineplex.core; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitScheduler; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import mineplex.core.command.CommandCenter; import mineplex.core.command.ICommand; import mineplex.core.common.util.F; @@ -15,6 +19,9 @@ import mineplex.core.common.util.UtilTime.TimeUnit; public abstract class MiniPlugin implements Listener { + private static final ExecutorService threadPool = Executors.newCachedThreadPool( + new ThreadFactoryBuilder().setNameFormat("MiniPlugin Async %1$d").build()); + protected String _moduleName = "Default"; protected JavaPlugin _plugin; protected NautHashMap _commands; @@ -105,7 +112,8 @@ public abstract class MiniPlugin implements Listener public void runAsync(Runnable runnable) { - _plugin.getServer().getScheduler().runTaskAsynchronously(_plugin, runnable); + // Instead of using + threadPool.execute(runnable); } public void runAsync(Runnable runnable, long time)