我有一个使用Netty构建的服务器,其线程池基于bossGroup / workerGroup模型。哪个是基本的Netty服务器实现:
EventLoopGroup bossGroup = new NioEventLoopGroup(poolSize);
EventLoopGroup workerGroup = new NioEventLoopGroup(poolSize);
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new TelnetServerInitializer());
b.bind(PORT);
如果我想监视两个线程池bossGroup和workerPool的活动,那么活动线程计数和池大小是什么?我应该怎么做?
对于Java的ThreadPoolExecutor,我有:
ThreadPoolExecutor.getActiveCount()
ThreadPoolExecutor.getQueue.size()
对于EventLoopGroup,它还扩展了ExecutorService。有没有办法获取这些信息?
答案 0 :(得分:1)
如果您使用NioEventLoopGroup
/ EpollEventLoopGroup
/ KQueueEventLoopGroup
,则可以使用SingleThreadEventExecutor.pendingTasks()
:
您可以通过以下方式获取所有执行者:
EventLoopGroup.iterator()