我正在尝试编写一个 udp 服务器。我以这种方式配置了我的引导程序:
ChannelFactory factory = new NioDatagramChannelFactory(Executors.newCachedThreadPool());
ConnectionlessBootstrap bootstrap = new ConnectionlessBootstrap(factory);
bootstrap.setPipelineFactory(new UDPServerPipelineFactory());
bootstrap.setOption("sendBufferSize", 1048576*2);
bootstrap.setOption("receiveBufferSize", 1048576*2);
bootstrap.setOption("tcpNoDelay", true);
bootstrap.setOption("receiveBufferSizePredictorFactory", new AdaptiveReceiveBufferSizePredictorFactory(1048576, 1048576, 2000000));
bootstrap.bind(new InetSocketAddress(11000));
以这种方式流水线:
@Override
public ChannelPipeline getPipeline() throws Exception
{
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addFirst("execution-handler", new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(16, 2333444, 3444333)));
pipeline.addLast("decoder", new StringDecoder());
pipeline.addLast("counter", new UDPHandler());
return pipeline;
}
但是我的 UDPHandler 总是只由一个线程管理。我究竟做错了什么?