From e0e156a4205e751e0f780d243c339f290650f2dd Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 19 Feb 2023 14:47:06 +0100 Subject: [PATCH] Fix task scheduler, reject tasks above cap The ThreadPoolExecutor API is confusing with *very* common pitfalls, one of them being a setup like the one before completely blocking task execution while core task executors are working, not actually starting new threads. --- .../velocitypowered/proxy/scheduler/VelocityScheduler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java b/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java index ca69069ea..4d27a2ecf 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java @@ -34,9 +34,9 @@ import java.util.IdentityHashMap; import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; @@ -69,7 +69,7 @@ public class VelocityScheduler implements Scheduler { public VelocityScheduler(PluginManager pluginManager) { this.pluginManager = pluginManager; this.taskService = new ThreadPoolExecutor(1, MAX_SCHEDULER_POOLED_THREAD_CAP, - 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), + 60L, TimeUnit.SECONDS, new SynchronousQueue<>(), new ThreadFactoryBuilder().setDaemon(true) .setNameFormat("Velocity Task Scheduler - #%d").build()); this.timerExecutionService = Executors