Yes, you can. Here is an example:
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);
Note that you should not create a new ChannelFactory for each bootstrap instance created. You must reuse the factory.
Sharing a work pool between different connections means that the client socket and socket received by the socket server can be processed by the same I / O stream that belongs to the worker pool. This is usually a good idea, assuming that the handlers of these pipes do not spend too much time when they are called by an I / O stream.
However, if the handlers of a certain type of channel spend much more time than the handlers of other channels, you can observe pending responses from channels that did not receive a turn soon. This problem can be fixed by making sure that all handlers do not block and do their work as quickly as possible and return quickly.
source share