本文介绍了Netty是否可以将多个IO线程分配给同一通道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我要编码以下代码段:
If I were to code the following code segment:
class SimpleHandler extends SimpleChannelUpstreamHandler {
...
public static void main( String[] args ) throws Exception {
ServerBootstrap b = new ServerBootstrap(
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool(),
10 ));
b.setPipelineFactory( new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline( new SimpleHandler() );
}
});
b.bind( new InetSocketAddress( p ));
}
并假设以下情况:
- 通道C1已输入
- netty将线程T1分配给通道C1
- 线程T1从通道C1读取了所有输入后,尽管它仍在处理输入,但更多的输入到达了通道C1
我的问题是:netty是否将新线程分配给通道C1(假设线程池中有空闲线程)?
My question is: will netty assign a new thread to channel C1 (assuming there are free threads in the thread pool)?
预先感谢
推荐答案
一旦将线程/选择器分配给Channel,它将在其整个生命周期中使用相同的线程/选择器.因此,它将始终由同一时间提供服务.
Once a Thread / Selector is assigned to a Channel it will use the same during all of its life-time. So it will be served by the same all the time.
这篇关于Netty是否可以将多个IO线程分配给同一通道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!