问题描述
有没有一种方法可以限制netty用于客户端连接的线程数(Netty是连接到远程服务器的客户端).我正在使用1个NioEventLoopGroup
,它被传递到每个Bootstrap
中.每个引导程序都获得相同的ChannelInitializer
引用(我曾经为每个引导程序创建不同的初始化程序,但似乎可以很好地共享相同的引用).我已从Java应用程序连接到许多充当服务器的硬件设备.
Is there a way to limit how many threads netty uses for client connections (Netty is the client which connect to a remote server). I am using 1 NioEventLoopGroup
which is passed into each Bootstrap
. Each of those Bootstraps gets the same ChannelInitializer
reference (I used to create different initializers for each Bootstrap, but it seems to work fine sharing the same reference). I am connected from my Java application to many hardware devices which act as the server.
我注意到,目前使用的线程数最多为16个(我在8核计算机上,根据我的阅读,Netty默认使用2倍的内核数).根据我在日志记录中看到的名称,它们被命名为nioEventLoopGroup-2-1
至nioEventLoopGroup-2-16
.我连接的第17台服务器将再次在nioEventLoopGroup-2-1
上运行.
I have noticed that currently up to 16 threads are used (I am on an 8 core machine, from what I have read Netty uses 2 times the number of cores by default). They are named nioEventLoopGroup-2-1
to nioEventLoopGroup-2-16
from what I see in my logging. The 17th server I connect to will run on nioEventLoopGroup-2-1
again.
1)是否有方法可以更改使用的默认线程?
1) Is there a way to change this default of threads used?
2)知道为什么该组从2开始计数吗?
2) Any idea why the group starts to count from 2?
推荐答案
如果您将1传递给NioEventLoopGroup并在引导程序之间共享实例,则将仅使用一个客户端.
If you pass 1 to the NioEventLoopGroup and share the instance between the bootstraps only one client will be used.
这篇关于如何限制Netty用于客户端连接的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!