我想在我的应用程序中重用ExecutorService.
我尝试用netty 4重现上面发布的代码,但我没有找到办法,我也谷歌搜索了很多,但似乎我们不能提供ExecutorService到bootstrap或NioEventLoopGroup对象.
例如,netty 3就是如何共享executorservice的:
ExecutorService executor = Executors.newCachedThreadPool();
NioClientBossPool clientBossPool = new NioClientBossPool(executor, clientBossCount);
NioServerBossPool serverBossPool = new NioServerBossPool(executor, serverBossCount);
NioWorkerPool workerPool = new NioWorkerPool(executor, workerCount);
ChannelFactory cscf = new NioClientSocketChannelFactory(clientBossPool, workerPool);
ChannelFactory sscf = new NioServerSocketChannelFactory(serverBossPool, workerPool);
...
ClientBootstrap cb = new ClientBootstrap(cscf);
ServerBootstrap sb = new ServerBootstrap(sscf);
Run Code Online (Sandbox Code Playgroud)
但是对于netty 4,据我所知你不能使用executorservice ...你必须提供像NioEventLoopGroup这样的EventLoop实现,但我真的想使用我将在我的应用程序中使用的通用executorService.因为我希望在一个线程池中让线程做不同类型的工作:计算,网络与netty ...
EventLoopGroup bossGroup = new NioEventLoopGroup(); // (1)
EventLoopGroup workerGroup = new NioEventLoopGroup()
ServerBootstrap b = new ServerBootstrap(); // (2)
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class) // (3)
.childHandler(new …Run Code Online (Sandbox Code Playgroud)