Reputation: 580
I am using Netty 4 in my project. I found that it assigns a single thread to each channel(connection) and uses it for both receiving and sending data.
In my application i get requests from channel, process them in different threads(my own threads) and then send responses back through the same channel. Because of using one thread for inbound and outbound, processing received packets waits when thread is sending packets.
Is there any way to use 2 thread for each channel, One for receive (inbound data processing) and one for send (outbound data processing)?
Upvotes: 1
Views: 1836
Reputation: 324
With different EventExecutorGroup you can put send and receive handler logic into different threads, i.e. send handler in one EventExecutorGroup and write handler in another.
But usually for sending is pretty fast and you don't need to use your own thread. For receiving and the consecutive while lengthy processing, you probably will need to use your own thread by putting the logic into a DefaultEventExecutorGroup that provides a pool of threads to be used by all connected channels while giving one thread for one such channel only.
Example code below:
final EventExecutorGroup bizEventLoopGroup = new DefaultEventExecutorGroup(50);
public void initChannel(Channel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
//other code...
p.addLast(bizEventLoopGroup, LOGIN_HANDLER, new LoginHandler());
//LoginHandler is time-consuming since it will need to ensure sending back all previously cached message.
Upvotes: 2
Reputation: 580
I found that it use only one thread for read and write, and there is no method for changing it.
Upvotes: 0