Reputation: 26858
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.
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) Is there a way to change this default of threads used?
2) Any idea why the group starts to count from 2?
Upvotes: 2
Views: 2526
Reputation: 26858
I saw in the source code that it is also possible to set it via a System property: io.netty.eventLoopThreads
Upvotes: 0
Reputation: 23557
If you pass 1 to the NioEventLoopGroup and share the instance between the bootstraps only one client will be used.
Upvotes: 2