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:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user