From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com> Date: Tue, 31 Dec 2024 00:00:00 -0800 Subject: [PATCH] Virtual thread for User Authenticator diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java index 0afd30a9a4eb7de7e58e1b91342cca51c771f300..e442fd1b80dd57d4420cab4da69ec3598ffc22d3 100644 --- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java @@ -76,7 +76,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, // CraftBukkit end private static final AtomicInteger UNIQUE_THREAD_ID = new AtomicInteger(0); static final Logger LOGGER = LogUtils.getLogger(); - private static final java.util.concurrent.ExecutorService authenticatorPool = java.util.concurrent.Executors.newCachedThreadPool(new com.google.common.util.concurrent.ThreadFactoryBuilder().setNameFormat("User Authenticator #%d").setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)).build()); // Paper - Cache authenticator threads + private static final java.util.concurrent.ExecutorService authenticatorPool = java.util.concurrent.Executors.newCachedThreadPool(new com.google.common.util.concurrent.ThreadFactoryBuilder().setNameFormat("User Authenticator #%d").setThreadFactory(org.dreeam.leaf.config.modules.opt.VT4UserAuthenticator.enabled ? Thread.ofVirtual().factory() : java.util.concurrent.Executors.defaultThreadFactory()).setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)).build()); // Paper - Cache authenticator threads // Leaf - Virtual thread for User Authenticator private static final int MAX_TICKS_BEFORE_LOGIN = 600; private final byte[] challenge; final MinecraftServer server; diff --git a/src/main/java/org/dreeam/leaf/config/modules/opt/VT4UserAuthenticator.java b/src/main/java/org/dreeam/leaf/config/modules/opt/VT4UserAuthenticator.java new file mode 100644 index 0000000000000000000000000000000000000000..751549c6ddacc40b64dc230064f5eeb6b1a2efca --- /dev/null +++ b/src/main/java/org/dreeam/leaf/config/modules/opt/VT4UserAuthenticator.java @@ -0,0 +1,21 @@ +package org.dreeam.leaf.config.modules.opt; + +import org.dreeam.leaf.config.ConfigModules; +import org.dreeam.leaf.config.EnumConfigCategory; + +public class VT4UserAuthenticator extends ConfigModules { + + public String getBasePath() { + return EnumConfigCategory.PERF.getBaseKeyName(); + } + + public static boolean enabled = true; + + @Override + public void onLoaded() { + enabled = config.getBoolean(getBasePath() + ".use-virtual-thread-for-user-authenticator", enabled, + config.pickStringRegionBased( + "Use the new Virtual Thread introduced in JDK 21 for User Authenticator.", + "是否为用户验证器使用虚拟线程.")); + } +}