From 48be22a63ec1e323a99605478aa72150280e7a28 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Mon, 16 Dec 2024 08:29:06 -0800 Subject: [PATCH] Use forkjoin thread pool for background executor ForkJoin thread pools are specially handled with CompletableFuture. Specifically, join()/get() calls will allow work stealing from other fork join threads. This fixes a deadlock where the worldgen worker is waiting on the I/O worker. --- .../sources/net/minecraft/Util.java.patch | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/Util.java.patch b/paper-server/patches/sources/net/minecraft/Util.java.patch index bcf7f18858..946139d552 100644 --- a/paper-server/patches/sources/net/minecraft/Util.java.patch +++ b/paper-server/patches/sources/net/minecraft/Util.java.patch @@ -37,7 +37,7 @@ } public static long getEpochMillis() { -@@ -146,15 +_,17 @@ +@@ -146,9 +_,10 @@ return FILENAME_DATE_TIME_FORMATTER.format(ZonedDateTime.now()); } @@ -50,22 +50,16 @@ if (i <= 0) { directExecutorService = MoreExecutors.newDirectExecutorService(); } else { - AtomicInteger atomicInteger = new AtomicInteger(1); -- directExecutorService = new ForkJoinPool(i, forkJoinPool -> { -- final String string = "Worker-" + name + "-" + atomicInteger.getAndIncrement(); -+ directExecutorService = Executors.newFixedThreadPool(i, target -> new io.papermc.paper.util.ServerWorkerThread(target, name, priorityModifier)); -+ } -+ /* final String string = "Worker-" + name + "-" + atomicInteger.getAndIncrement(); - ForkJoinWorkerThread forkJoinWorkerThread = new ForkJoinWorkerThread(forkJoinPool) { - @Override - protected void onStart() { -@@ -176,13 +_,27 @@ +@@ -173,16 +_,30 @@ + super.onTermination(throwOnTermination); + } + }; ++ forkJoinWorkerThread.setPriority(Thread.NORM_PRIORITY + priorityModifier); // Paper - Deprioritize over main forkJoinWorkerThread.setName(string); return forkJoinWorkerThread; - }, Util::onThreadException, true); -- } -+ }*/ -+ // Paper end +- }, Util::onThreadException, true); ++ }, Util::onThreadException, true, 0, Integer.MAX_VALUE, 1, null, 365, TimeUnit.DAYS); // Paper - do not expire threads + } return new TracingExecutor(directExecutorService); }