Skip to content

Commit

Permalink
misc: 延长批处理间隔时间,调整查询Profile用的线程数量
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Oct 14, 2024
1 parent 26e398e commit d5d03dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private void load()
{
Bukkit.getAsyncScheduler().runAtFixedRate(plugin,
task -> this.batchPlayerInfo(),
1000, 1000,
1500, 1500,
TimeUnit.MILLISECONDS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import org.jetbrains.annotations.Nullable;
import xyz.nifeather.morph.MorphPlugin;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

public class ProfileLookupExecutor
Expand All @@ -16,22 +14,30 @@ public static ExecutorService executor()
{
var executor = EXECUTOR;
if (executor == null || executor.isShutdown())
{
EXECUTOR = executor = createExecutor();
}

return executor;
}

private static int getThreadCount()
{
return Math.max(4, Runtime.getRuntime().availableProcessors() / 2);
}

private static ExecutorService createExecutor()
{
return Executors.newFixedThreadPool(5, new ThreadFactory()
return Executors.newFixedThreadPool(getThreadCount(), new ThreadFactory()
{
private final AtomicInteger threadCount = new AtomicInteger(0);

@Override
public Thread newThread(@NotNull Runnable runnable)
{
Thread thread = new Thread(runnable);
thread.setName("FeatherMorph Profile Executor #" + this.threadCount.getAndIncrement());
var threadId = this.threadCount.getAndIncrement();
thread.setName("FeatherMorph Profile Executor #" + threadId);

thread.setUncaughtExceptionHandler((Thread t, Throwable error) ->
{
Expand Down

0 comments on commit d5d03dc

Please sign in to comment.