3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-16 21:10:30 +01:00

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.
Dieser Commit ist enthalten in:
Nassim Jahnke 2023-02-19 14:47:06 +01:00
Ursprung b0988bc50a
Commit e0e156a420
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B

Datei anzeigen

@ -34,9 +34,9 @@ import java.util.IdentityHashMap;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -69,7 +69,7 @@ public class VelocityScheduler implements Scheduler {
public VelocityScheduler(PluginManager pluginManager) { public VelocityScheduler(PluginManager pluginManager) {
this.pluginManager = pluginManager; this.pluginManager = pluginManager;
this.taskService = new ThreadPoolExecutor(1, MAX_SCHEDULER_POOLED_THREAD_CAP, this.taskService = new ThreadPoolExecutor(1, MAX_SCHEDULER_POOLED_THREAD_CAP,
60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), 60L, TimeUnit.SECONDS, new SynchronousQueue<>(),
new ThreadFactoryBuilder().setDaemon(true) new ThreadFactoryBuilder().setDaemon(true)
.setNameFormat("Velocity Task Scheduler - #%d").build()); .setNameFormat("Velocity Task Scheduler - #%d").build());
this.timerExecutionService = Executors this.timerExecutionService = Executors