转:Netty服务器线程模型概览
一切从ServerBootstrap开始 ServerBootstrap 负责初始话netty服务器,并且开始监听端口的socket请求。 Java代码 bootstrap bootstrap = new ServerBootstrap( new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), //boss线程池 Executors.newCachedThreadPool() //worker线程池 ) ); bootstrap.setPipelineFactory( new HttpChannelPipelineFactory()); bootstrap.setOption( "child.tcpNoDelay" , true ); bootstrap.setOption( "child.keepAlive" , true ); bootstrap.bind( new InetSocketAddress(httpPort)); //端口开始监听 ServerBootstrap 用一个ServerSocketChannelFactory 来实例化。ServerSocketChannelFactory 有两种选择,一种是NioServerSocketChannelFactory