(Jettpack) Use MCUtil.asyncExecutor for MAIN_WORKER_EXECUTOR in SystemUtils
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Etil <81570777+etil2jz@users.noreply.github.com>
|
||||
Date: Tue, 21 Sep 2021 17:25:02 +0200
|
||||
Subject: [PATCH] (Jettpack) Use MCUtil.asyncExecutor for MAIN_WORKER_EXECUTOR
|
||||
in SystemUtils
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/Util.java b/src/main/java/net/minecraft/Util.java
|
||||
index af598369e5aeae700d7d9da049f173fc51b7a370..4e8b794eb268abf2bbca83dfef1a3c33e6d0c327 100644
|
||||
--- a/src/main/java/net/minecraft/Util.java
|
||||
+++ b/src/main/java/net/minecraft/Util.java
|
||||
@@ -62,6 +62,10 @@ import net.minecraft.world.level.block.state.properties.Property;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
+import java.util.concurrent.AbstractExecutorService;
|
||||
+import net.minecraft.server.ServerWorkerWrapper;
|
||||
+import net.minecraft.server.MCUtil;
|
||||
+import java.util.Collections;
|
||||
|
||||
public class Util {
|
||||
private static final AtomicInteger WORKER_COUNT = new AtomicInteger(1);
|
||||
@@ -139,7 +143,45 @@ public class Util {
|
||||
if (i <= 0) {
|
||||
executorService = MoreExecutors.newDirectExecutorService();
|
||||
} else {
|
||||
- executorService = new java.util.concurrent.ThreadPoolExecutor(i, i,0L, TimeUnit.MILLISECONDS, new java.util.concurrent.LinkedBlockingQueue<Runnable>(), target -> new ServerWorkerThread(target, s, priorityModifier));
|
||||
+ //executorService = new java.util.concurrent.ThreadPoolExecutor(i, i,0L, TimeUnit.MILLISECONDS, new java.util.concurrent.LinkedBlockingQueue<Runnable>(), target -> new ServerWorkerThread(target, s, priorityModifier));
|
||||
+ executorService = Integer.getInteger("Paper.WorkerThreadCount", i) <= 0 ? MoreExecutors.newDirectExecutorService() : new AbstractExecutorService(){
|
||||
+ private volatile boolean shutdown = false;
|
||||
+
|
||||
+ @Override
|
||||
+ public final List<Runnable> shutdownNow() {
|
||||
+ this.shutdown = true;
|
||||
+ return Collections.emptyList();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public final void shutdown() {
|
||||
+ this.shutdown = true;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public final boolean isShutdown() {
|
||||
+ return this.shutdown;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public final boolean isTerminated() {
|
||||
+ return this.shutdown;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public final boolean awaitTermination(long l2, TimeUnit timeUnit) throws InterruptedException {
|
||||
+ if (!this.shutdown) {
|
||||
+ throw new UnsupportedOperationException();
|
||||
+ }
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public final void execute(Runnable runnable) {
|
||||
+ MCUtil.asyncExecutor.execute(new ServerWorkerWrapper(runnable));
|
||||
+ }
|
||||
+ };
|
||||
+
|
||||
}
|
||||
/*
|
||||
@Override
|
||||
diff --git a/src/main/java/net/minecraft/server/ServerWorkerWrapper.java b/src/main/java/net/minecraft/server/ServerWorkerWrapper.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..d6344b4426cf88027b18dc69a0d4be9fa57bd3a4
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/minecraft/server/ServerWorkerWrapper.java
|
||||
@@ -0,0 +1,24 @@
|
||||
+package net.minecraft.server;
|
||||
+
|
||||
+import com.google.common.base.Preconditions;
|
||||
+import net.minecraft.Util;
|
||||
+
|
||||
+public final class ServerWorkerWrapper implements Runnable {
|
||||
+ private final Runnable internalRunnable;
|
||||
+
|
||||
+ public ServerWorkerWrapper(Runnable runnable) {
|
||||
+ this.internalRunnable = Preconditions.checkNotNull(runnable, "internalRunnable");
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public final void run() {
|
||||
+ try {
|
||||
+ this.internalRunnable.run();
|
||||
+ return;
|
||||
+ }
|
||||
+ catch (Throwable throwable) {
|
||||
+ Util.onThreadException(Thread.currentThread(), throwable);
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
\ No newline at end of file
|
||||
Reference in New Issue
Block a user