From d5d03dc4cf01240341626077f35acd71c35d4fe4 Mon Sep 17 00:00:00 2001 From: MATRIX-feather Date: Mon, 14 Oct 2024 18:59:24 +0800 Subject: [PATCH] =?UTF-8?q?misc:=20=E5=BB=B6=E9=95=BF=E6=89=B9=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=97=B4=E9=9A=94=E6=97=B6=E9=97=B4=EF=BC=8C=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E6=9F=A5=E8=AF=A2Profile=E7=94=A8=E7=9A=84=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../morph/misc/skins/PlayerSkinProvider.java | 2 +- .../morph/misc/skins/ProfileLookupExecutor.java | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/xyz/nifeather/morph/misc/skins/PlayerSkinProvider.java b/src/main/java/xyz/nifeather/morph/misc/skins/PlayerSkinProvider.java index da3cdfb9..96a4f688 100644 --- a/src/main/java/xyz/nifeather/morph/misc/skins/PlayerSkinProvider.java +++ b/src/main/java/xyz/nifeather/morph/misc/skins/PlayerSkinProvider.java @@ -49,7 +49,7 @@ private void load() { Bukkit.getAsyncScheduler().runAtFixedRate(plugin, task -> this.batchPlayerInfo(), - 1000, 1000, + 1500, 1500, TimeUnit.MILLISECONDS); } diff --git a/src/main/java/xyz/nifeather/morph/misc/skins/ProfileLookupExecutor.java b/src/main/java/xyz/nifeather/morph/misc/skins/ProfileLookupExecutor.java index 36a9ca02..cc2e775e 100644 --- a/src/main/java/xyz/nifeather/morph/misc/skins/ProfileLookupExecutor.java +++ b/src/main/java/xyz/nifeather/morph/misc/skins/ProfileLookupExecutor.java @@ -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 @@ -16,14 +14,21 @@ 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); @@ -31,7 +36,8 @@ private static ExecutorService createExecutor() 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) -> {