Netty 4 code to start blocking operations in a thread pool

The documentation does not give any details about the types of artists available. I want to have an executor based on a custom thread pool, like MemoryAwareThreadPoolExecutor, which was in netty 3.

How can I do it?

+4
source share
1 answer

When you add a handler to the pipeline, you can specify an EventExecutorGroup along with the handler:

 EventExecutorGroup executor = new DefaultEventExecutorGroup(...); ... ChannelPipeline p = ch.pipeline(); p.addLast(executor, new MyHandler()); 

EventExecutorGroup is similar to OrderedMemoryAwareThreadPoolExecutor , except that it does not apply any memory restrictions. You will have to implement your own handler to ensure memory limitations - MemoryAwareThreadPoolExecutor was not very efficient and often had performance problems.

There is no replacement for MemoryAwareThreadPoolExecutor because all handler methods in Netty 4 are called sequentially for the same connection. If you want to perform unordered execution, you will have to pass tasks to java.util.concurrent.Executor . This decision is intentional - otherwise, the implementation of the handler cannot make any consumption of thread safety.

+6
source

All Articles