3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Use custom ThreadFactory that does FastThreadLocal wrapping for us

This primarily has the benefit of not giving threads strange names
Dieser Commit ist enthalten in:
Andrew Steinborn 2019-07-02 09:10:00 -04:00
Ursprung 190f2fee75
Commit a63e905edf
2 geänderte Dateien mit 25 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -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() {

Datei anzeigen

@ -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);
}
}