Reputation: 27375
I'm trying to use Oio in my Server Netty-based application. I\m currently using it as follows:
String host: String = //...
int port = //...
ServerBootstrap server = new ServerBootstrap()
.group(new OioEventLoopGroup(), new OioEventLoopGroup())
.localAddress(new InetSocketAddress(host, port))
.channel(OioServerSocketChannel.class)
.childHandler(new ChannelInitializer<Channel>() {
public void initChannel(Channel ch){
ch.pipeline()
//adding handlers
}
})
server.bind().sync()
The thing is the number of threads will grow without any bounds. But I want to restrict it to, say 64. If more than 64 clients will try to connect I want to do something (probably respond with connection refused)
Is there a way to control the number of threads in Netty Oio?
Upvotes: 1
Views: 114
Reputation: 5649
You can try creating the OioEventGroup with a limit i.e. use either of the below constructors
public OioEventLoopGroup(int maxChannels)
or
public OioEventLoopGroup(int maxChannels,
java.util.concurrent.ThreadFactory threadFactory)
Link to the documentation.
Currently, you are creating it with no limit, so threads are growing without any bound.
Upvotes: 2