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.
This commit is contained in:
Spottedleaf 2024-12-16 08:29:06 -08:00
parent 783b3b70e6
commit 48be22a63e

View file

@ -37,7 +37,7 @@
} }
public static long getEpochMillis() { public static long getEpochMillis() {
@@ -146,15 +_,17 @@ @@ -146,9 +_,10 @@
return FILENAME_DATE_TIME_FORMATTER.format(ZonedDateTime.now()); return FILENAME_DATE_TIME_FORMATTER.format(ZonedDateTime.now());
} }
@ -50,22 +50,16 @@
if (i <= 0) { if (i <= 0) {
directExecutorService = MoreExecutors.newDirectExecutorService(); directExecutorService = MoreExecutors.newDirectExecutorService();
} else { } else {
AtomicInteger atomicInteger = new AtomicInteger(1); @@ -173,16 +_,30 @@
- directExecutorService = new ForkJoinPool(i, forkJoinPool -> { super.onTermination(throwOnTermination);
- final String string = "Worker-" + name + "-" + atomicInteger.getAndIncrement(); }
+ directExecutorService = Executors.newFixedThreadPool(i, target -> new io.papermc.paper.util.ServerWorkerThread(target, name, priorityModifier)); };
+ } + forkJoinWorkerThread.setPriority(Thread.NORM_PRIORITY + priorityModifier); // Paper - Deprioritize over main
+ /* final String string = "Worker-" + name + "-" + atomicInteger.getAndIncrement();
ForkJoinWorkerThread forkJoinWorkerThread = new ForkJoinWorkerThread(forkJoinPool) {
@Override
protected void onStart() {
@@ -176,13 +_,27 @@
forkJoinWorkerThread.setName(string); forkJoinWorkerThread.setName(string);
return forkJoinWorkerThread; return forkJoinWorkerThread;
}, Util::onThreadException, true); - }, Util::onThreadException, true);
- } + }, Util::onThreadException, true, 0, Integer.MAX_VALUE, 1, null, 365, TimeUnit.DAYS); // Paper - do not expire threads
+ }*/ }
+ // Paper end
return new TracingExecutor(directExecutorService); return new TracingExecutor(directExecutorService);
} }