mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 11:38:03 +01:00
Use a common pool instead of creating new threads on every chunk save
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
5d15e76323
commit
8dcc3000cf
@ -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);
|
||||
|
@ -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<Void> saveChunks(@NotNull Collection<Chunk> 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();
|
||||
|
Loading…
Reference in New Issue
Block a user