9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-25 09:59:15 +00:00

Use a dedicated thread pool for PWT event rescheduling

This commit is contained in:
HaHaWTH
2025-04-26 07:32:35 +14:00
parent b17a0b3550
commit 97f0017519
3 changed files with 39 additions and 12 deletions

View File

@@ -0,0 +1,35 @@
package org.dreeam.leaf.async.world;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class PWTEventScheduler {
private static volatile PWTEventScheduler instance;
private final ExecutorService executor;
private PWTEventScheduler() {
this.executor = Executors.newCachedThreadPool(
new ThreadFactoryBuilder()
.setNameFormat("Leaf PWT Event Scheduler Thread - %d")
.setDaemon(true)
.setPriority(Thread.NORM_PRIORITY - 2)
.build()
);
}
public static PWTEventScheduler getScheduler() {
if (instance == null) {
synchronized (PWTEventScheduler.class) {
if (instance == null) {
instance = new PWTEventScheduler();
}
}
}
return instance;
}
public void scheduleTask(Runnable task) {
this.executor.execute(task);
}
}