perf: 优化性能
This commit is contained in:
@@ -3,9 +3,10 @@ setArchivesBaseName("HamsterBall-Common")
|
||||
dependencies {
|
||||
// https://mvnrepository.com/artifact/com.google.code.gson/gson
|
||||
//noinspection GradlePackageUpdate
|
||||
//noinspection VulnerableLibrariesLocal
|
||||
compileOnly 'com.google.code.gson:gson:2.8.0'
|
||||
// https://mvnrepository.com/artifact/io.netty/netty-all
|
||||
compileOnly 'io.netty:netty-all:4.1.82.Final'
|
||||
compileOnly 'io.netty:netty-all:4.1.86.Final'
|
||||
|
||||
compileOnly "cn.hamster3.mc.plugin.core:common:${hamster_core_version}"
|
||||
|
||||
|
@@ -13,9 +13,6 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class BallChannelInitializer extends ChannelInitializer<SocketChannel> {
|
||||
public BallChannelInitializer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initChannel(@NotNull SocketChannel channel) {
|
||||
channel.pipeline()
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.utils;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.common.thread.NamedThreadFactory;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.ServerChannel;
|
||||
@@ -14,12 +15,16 @@ import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
public enum OS {
|
||||
WINDOWS,
|
||||
LINUX,
|
||||
MACOS,
|
||||
OTHER;
|
||||
|
||||
private static final ThreadFactory THREAD_FACTORY = new NamedThreadFactory("HamsterBall-IO");
|
||||
|
||||
@NotNull
|
||||
public static OS getCurrentOS() {
|
||||
String s = System.getProperties().get("os.name").toString().toLowerCase();
|
||||
@@ -50,11 +55,11 @@ public enum OS {
|
||||
public EventLoopGroup getEventLoopGroup(int nThread) {
|
||||
switch (this) {
|
||||
case LINUX:
|
||||
return new EpollEventLoopGroup(nThread);
|
||||
return new EpollEventLoopGroup(nThread, THREAD_FACTORY);
|
||||
case MACOS:
|
||||
return new KQueueEventLoopGroup(nThread);
|
||||
return new KQueueEventLoopGroup(nThread, THREAD_FACTORY);
|
||||
default:
|
||||
return new NioEventLoopGroup(nThread);
|
||||
return new NioEventLoopGroup(nThread, THREAD_FACTORY);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user