【问题标题】:Can netty assign multiple IO threads to the same Channel?netty可以给同一个Channel分配多个IO线程吗?
【发布时间】:2012-12-14 16:04:30
【问题描述】:

如果我要编写以下代码段:

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分配一个新线程(假设线程池中有空闲线程)?

提前致谢

【问题讨论】:

    标签: netty


    【解决方案1】:

    一旦将线程/选择器分配给通道,它将在其整个生命周期中使用相同的。所以它会一直由同一个服务。

    【讨论】:

    猜你喜欢
    • 2015-11-26
    • 1970-01-01
    • 2020-12-31
    • 2021-03-18
    • 1970-01-01
    • 2013-04-07
    • 2023-03-27
    • 1970-01-01
    • 2023-03-19
    相关资源
    最近更新 更多