Netty UDP 服务端 运行一段时间后占用CPU使用率很高,求解答,
public void start() throws Exception {
final NioEventLoopGroup group = new NioEventLoopGroup();
try {
//启动数据处理线程
new YjInfoHandleThread(yjUserLoginMongodbService);
final Bootstrap b = new Bootstrap();
b.group(group).channel(NioDatagramChannel.class)
.option(ChannelOption.SO_BROADCAST, true)
.handler(new ChannelInitializer<NioDatagramChannel>() {
@Override
public void initChannel(final NioDatagramChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new ServerHandler(yjUserLoginMongodbService));
}
});
LOGGER.warn("启动UDP 服务端........................."+port);
// Bind and start to accept incoming connections.
//InetAddress address = InetAddress.getLocalHost();
// Channel channel= b.bind(address,port).sync().channel();
b.bind(port).sync().channel().closeFuture().await();
} finally {
group.shutdownGracefully();
System.out.print("In Server Finally");
}
}
p.addLast(new ServerHandler(yjUserLoginMongodbService));
每来一个连接就会创建一个ServerHandler,是不是这个影响的?
最近也在学习Netty,了解到@sharable注解,Handler共享,具体你可以自行谷歌