diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/TransportType.java b/proxy/src/main/java/com/velocitypowered/proxy/network/TransportType.java index 88bfc8f31..e382a4856 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/TransportType.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/TransportType.java @@ -1,6 +1,6 @@ package com.velocitypowered.proxy.network; -import com.google.common.util.concurrent.ThreadFactoryBuilder; +import com.velocitypowered.proxy.util.concurrent.VelocityNettyThreadFactory; import io.netty.channel.EventLoopGroup; import io.netty.channel.epoll.Epoll; import io.netty.channel.epoll.EpollDatagramChannel; @@ -19,7 +19,6 @@ import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; -import io.netty.util.concurrent.DefaultThreadFactory; import java.util.concurrent.ThreadFactory; import java.util.function.BiFunction; @@ -61,7 +60,7 @@ enum TransportType { } private static ThreadFactory createThreadFactory(final String name, final Type type) { - return new DefaultThreadFactory("Netty " + name + ' ' + type.toString(), false); + return new VelocityNettyThreadFactory("Netty " + name + ' ' + type.toString() + " #%d"); } public static TransportType bestType() { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/concurrent/VelocityNettyThreadFactory.java b/proxy/src/main/java/com/velocitypowered/proxy/util/concurrent/VelocityNettyThreadFactory.java new file mode 100644 index 000000000..87fb83524 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/concurrent/VelocityNettyThreadFactory.java @@ -0,0 +1,23 @@ +package com.velocitypowered.proxy.util.concurrent; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.netty.util.concurrent.FastThreadLocalThread; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicInteger; + +public class VelocityNettyThreadFactory implements ThreadFactory { + + private final AtomicInteger threadNumber = new AtomicInteger(); + private final String nameFormat; + + public VelocityNettyThreadFactory(String nameFormat) { + this.nameFormat = checkNotNull(nameFormat, "nameFormat"); + } + + @Override + public Thread newThread(Runnable r) { + String name = String.format(nameFormat, threadNumber.incrementAndGet()); + return new FastThreadLocalThread(r, name); + } +}