From 7ac0834123fa27cf1d6700ac3e0474e13cd379dc Mon Sep 17 00:00:00 2001 From: TheMode Date: Sun, 9 May 2021 00:11:35 +0200 Subject: [PATCH] Dont hardcode thread count --- .../java/net/minestom/server/MinecraftServer.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minestom/server/MinecraftServer.java b/src/main/java/net/minestom/server/MinecraftServer.java index c8c69b092..5f7197cbd 100644 --- a/src/main/java/net/minestom/server/MinecraftServer.java +++ b/src/main/java/net/minestom/server/MinecraftServer.java @@ -78,13 +78,15 @@ public final class MinecraftServer { public static final String THREAD_NAME_TICK = "Ms-Tick"; public static final String THREAD_NAME_BLOCK_BATCH = "Ms-BlockBatchPool"; - public static final int THREAD_COUNT_BLOCK_BATCH = 4; + public static final int THREAD_COUNT_BLOCK_BATCH = getThreadCount("minestom.block-thread-count", + Runtime.getRuntime().availableProcessors() / 2); public static final String THREAD_NAME_SCHEDULER = "Ms-SchedulerPool"; - public static final int THREAD_COUNT_SCHEDULER = 1; + public static final int THREAD_COUNT_SCHEDULER = getThreadCount("minestom.scheduler-thread-count", + Runtime.getRuntime().availableProcessors() / 2); public static final String THREAD_NAME_PARALLEL_CHUNK_SAVING = "Ms-ParallelChunkSaving"; - public static final int THREAD_COUNT_PARALLEL_CHUNK_SAVING = 4; + public static final int THREAD_COUNT_PARALLEL_CHUNK_SAVING = getThreadCount("minestom.save-thread-count", 2); // Config // Can be modified at performance cost when increased @@ -823,4 +825,8 @@ public final class MinecraftServer { "You cannot access the manager before MinecraftServer#init, " + "if you are developing an extension be sure to retrieve them at least after Extension#preInitialize");*/ } + + private static int getThreadCount(@NotNull String property, int count) { + return Integer.getInteger(property, Math.min(1, count)); + } }