9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-25 01:49:16 +00:00

Remove redundant full-qualified name & Higher priority for async tasks

This commit is contained in:
HaHaWTH
2025-05-27 04:05:52 +14:00
parent 519ddbf58b
commit c1297d728e
2 changed files with 9 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
package org.dreeam.leaf.async.chunk;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import net.minecraft.Util;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -14,13 +15,13 @@ public class AsyncChunkSend {
public static final ExecutorService POOL = new ThreadPoolExecutor(
1, 1, 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(),
new com.google.common.util.concurrent.ThreadFactoryBuilder()
.setPriority(Thread.NORM_PRIORITY - 2)
new ThreadFactoryBuilder()
.setPriority(Thread.NORM_PRIORITY)
.setNameFormat("Leaf Async Chunk Send Thread")
.setUncaughtExceptionHandler(Util::onThreadException)
.setThreadFactory(AsyncChunkSendThread::new)
.build(),
new ThreadPoolExecutor.DiscardPolicy()
new ThreadPoolExecutor.CallerRunsPolicy()
);
public static final Logger LOGGER = LogManager.getLogger("Leaf Async Chunk Send");
}

View File

@@ -5,6 +5,7 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.world.level.pathfinder.Path;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dreeam.leaf.config.modules.async.AsyncPathfinding;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -29,8 +30,8 @@ public class AsyncPathProcessor {
private static long lastWarnMillis = System.currentTimeMillis();
private static final ThreadPoolExecutor pathProcessingExecutor = new ThreadPoolExecutor(
1,
org.dreeam.leaf.config.modules.async.AsyncPathfinding.asyncPathfindingMaxThreads,
org.dreeam.leaf.config.modules.async.AsyncPathfinding.asyncPathfindingKeepalive, TimeUnit.SECONDS,
AsyncPathfinding.asyncPathfindingMaxThreads,
AsyncPathfinding.asyncPathfindingKeepalive, TimeUnit.SECONDS,
getQueueImpl(),
new ThreadFactoryBuilder()
.setNameFormat(THREAD_PREFIX + " Thread - %d")
@@ -44,7 +45,7 @@ public class AsyncPathProcessor {
public void rejectedExecution(Runnable rejectedTask, ThreadPoolExecutor executor) {
BlockingQueue<Runnable> workQueue = executor.getQueue();
if (!executor.isShutdown()) {
switch (org.dreeam.leaf.config.modules.async.AsyncPathfinding.asyncPathfindingRejectPolicy) {
switch (AsyncPathfinding.asyncPathfindingRejectPolicy) {
case FLUSH_ALL -> {
if (!workQueue.isEmpty()) {
List<Runnable> pendingTasks = new ArrayList<>(workQueue.size());
@@ -98,7 +99,7 @@ public class AsyncPathProcessor {
}
private static BlockingQueue<Runnable> getQueueImpl() {
final int queueCapacity = org.dreeam.leaf.config.modules.async.AsyncPathfinding.asyncPathfindingQueueSize;
final int queueCapacity = AsyncPathfinding.asyncPathfindingQueueSize;
return new LinkedBlockingQueue<>(queueCapacity);
}