[FEATURE][EXPERIMENTAL] NettyThreadFactory

This commit is contained in:
Gravit 2020-09-26 02:47:19 +07:00
parent 3a3aafe5fa
commit 584e07328c
No known key found for this signature in database
GPG key ID: 98A079490768CCE5
3 changed files with 25 additions and 6 deletions

View file

@ -42,8 +42,8 @@ public LauncherNettyServer(LaunchServer server) {
if (config.performance.usingEpoll && !Epoll.isAvailable()) {
LogHelper.error("Epoll is not available: (netty,perfomance.usingEpoll configured wrongly)", Epoll.unavailabilityCause());
}
bossGroup = NettyObjectFactory.newEventLoopGroup(config.performance.bossThread);
workerGroup = NettyObjectFactory.newEventLoopGroup(config.performance.workerThread);
bossGroup = NettyObjectFactory.newEventLoopGroup(config.performance.bossThread, "LauncherNettyServer.bossGroup");
workerGroup = NettyObjectFactory.newEventLoopGroup(config.performance.workerThread, "LauncherNettyServer.workerGroup");
serverBootstrap = new ServerBootstrap();
service = new WebSocketService(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE), server);
serverBootstrap.group(bossGroup, workerGroup)

View file

@ -15,11 +15,11 @@ public static void setUsingEpoll(boolean value) {
epoll = value;
}
public static EventLoopGroup newEventLoopGroup(int threads) {
public static EventLoopGroup newEventLoopGroup(int threads, String poolName) {
if (epoll)
return new EpollEventLoopGroup(threads);
return new EpollEventLoopGroup(threads, new NettyThreadFactory(poolName));
else
return new NioEventLoopGroup(threads);
return new NioEventLoopGroup(threads, new NettyThreadFactory(poolName));
}
public static ChannelFactory<? extends ServerChannel> getServerSocketChannelFactory() {
@ -28,5 +28,4 @@ public static ChannelFactory<? extends ServerChannel> getServerSocketChannelFact
else
return NioServerSocketChannel::new;
}
}

View file

@ -0,0 +1,20 @@
package pro.gravit.launchserver.socket;
import io.netty.util.concurrent.DefaultThreadFactory;
import pro.gravit.utils.helper.LogHelper;
public class NettyThreadFactory extends DefaultThreadFactory {
public NettyThreadFactory(String poolName) {
super(poolName);
}
@Override
protected Thread newThread(Runnable r, String name) {
Thread thread = super.newThread(r, name);
thread.setUncaughtExceptionHandler((th, e) -> {
if(LogHelper.isDebugEnabled())
LogHelper.error(e);
});
return thread;
}
}