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

defer init tracker thread pool

This commit is contained in:
hayanesuru
2025-05-08 17:14:33 +09:00
parent 152fbed3d1
commit 2d2eda8069
2 changed files with 22 additions and 11 deletions

View File

@@ -23,20 +23,28 @@ public class MultithreadedTracker {
private static final String THREAD_PREFIX = "Leaf Async Tracker";
private static final Logger LOGGER = LogManager.getLogger(THREAD_PREFIX);
private static long lastWarnMillis = System.currentTimeMillis();
private static final ThreadPoolExecutor trackerExecutor = new ThreadPoolExecutor(
getCorePoolSize(),
getMaxPoolSize(),
getKeepAliveTime(), TimeUnit.SECONDS,
getQueueImpl(),
getThreadFactory(),
getRejectedPolicy()
);
private static ThreadPoolExecutor TRACKER_EXECUTOR = null;
private MultithreadedTracker() {
}
public static void init() {
if (TRACKER_EXECUTOR == null) {
TRACKER_EXECUTOR = new ThreadPoolExecutor(
getCorePoolSize(),
getMaxPoolSize(),
getKeepAliveTime(), TimeUnit.SECONDS,
getQueueImpl(),
getThreadFactory(),
getRejectedPolicy()
);
} else {
throw new IllegalStateException();
}
}
public static Executor getTrackerExecutor() {
return trackerExecutor;
return TRACKER_EXECUTOR;
}
public static void tick(ChunkSystemServerLevel level) {
@@ -59,7 +67,7 @@ public class MultithreadedTracker {
final Entity[] trackerEntitiesRaw = trackerEntities.getRawDataUnchecked();
// Move tracking to off-main
trackerExecutor.execute(() -> {
TRACKER_EXECUTOR.execute(() -> {
for (final Entity entity : trackerEntitiesRaw) {
if (entity == null) continue;
@@ -97,7 +105,7 @@ public class MultithreadedTracker {
}
// batch submit tasks
trackerExecutor.execute(() -> {
TRACKER_EXECUTOR.execute(() -> {
for (final Runnable sendChanges : sendChangesTasks) {
if (sendChanges == null) continue;

View File

@@ -57,5 +57,8 @@ public class MultithreadedTracker extends ConfigModules {
if (asyncEntityTrackerQueueSize <= 0)
asyncEntityTrackerQueueSize = asyncEntityTrackerMaxThreads * 384;
if (enabled) {
org.dreeam.leaf.async.tracker.MultithreadedTracker.init();
}
}
}