w1023607564 2019-05-23 15:03 采纳率: 0%
浏览 1768
已结题

Netty UDP 服务端 运行一段时间后占用CPU使用率很高

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");
    }
}
  • 写回答

1条回答 默认 最新

  • 听见温暖www 2019-05-23 15:24
    关注

    p.addLast(new ServerHandler(yjUserLoginMongodbService));
    每来一个连接就会创建一个ServerHandler,是不是这个影响的?
    最近也在学习Netty,了解到@sharable注解,Handler共享,具体你可以自行谷歌

    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作