From 8dcc3000cfbe932a24a582a0e22fa06cdee51456 Mon Sep 17 00:00:00 2001 From: TheMode Date: Fri, 17 Dec 2021 20:57:21 +0100 Subject: [PATCH] Use a common pool instead of creating new threads on every chunk save Signed-off-by: TheMode --- src/main/java/net/minestom/server/MinecraftServer.java | 3 --- src/main/java/net/minestom/server/instance/IChunkLoader.java | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/minestom/server/MinecraftServer.java b/src/main/java/net/minestom/server/MinecraftServer.java index 358bb28db..44bf97917 100644 --- a/src/main/java/net/minestom/server/MinecraftServer.java +++ b/src/main/java/net/minestom/server/MinecraftServer.java @@ -67,9 +67,6 @@ public final class MinecraftServer { public static final int THREAD_COUNT_BLOCK_BATCH = getThreadCount("minestom.block-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 = getThreadCount("minestom.save-thread-count", 2); - // Config // Can be modified at performance cost when increased public static final int TICK_PER_SECOND = Integer.getInteger("minestom.tps", 20); diff --git a/src/main/java/net/minestom/server/instance/IChunkLoader.java b/src/main/java/net/minestom/server/instance/IChunkLoader.java index dc64d00e0..2be534c0a 100644 --- a/src/main/java/net/minestom/server/instance/IChunkLoader.java +++ b/src/main/java/net/minestom/server/instance/IChunkLoader.java @@ -1,7 +1,6 @@ package net.minestom.server.instance; import net.minestom.server.MinecraftServer; -import net.minestom.server.thread.MinestomThreadPool; import net.minestom.server.utils.async.AsyncUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -9,6 +8,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; +import java.util.concurrent.ForkJoinPool; import java.util.concurrent.atomic.AtomicInteger; /** @@ -60,7 +60,7 @@ public interface IChunkLoader { */ default @NotNull CompletableFuture saveChunks(@NotNull Collection chunks) { if (supportsParallelSaving()) { - ExecutorService parallelSavingThreadPool = new MinestomThreadPool(MinecraftServer.THREAD_COUNT_PARALLEL_CHUNK_SAVING, MinecraftServer.THREAD_NAME_PARALLEL_CHUNK_SAVING, true); + ExecutorService parallelSavingThreadPool = ForkJoinPool.commonPool(); chunks.forEach(c -> parallelSavingThreadPool.execute(() -> saveChunk(c))); try { parallelSavingThreadPool.shutdown();