4

The documentation doesn't give any details on the different types of executors available. What I want is to have an executor that's based on a configurable thread pool, much like the MemoryAwareThreadPoolExecutor that was in netty 3.

How would I do that?

4

1 回答 1

6

当您将处理程序添加到管道时,您可以EventExecutorGroup与处理程序一起指定:

EventExecutorGroup executor = new DefaultEventExecutorGroup(...);
...

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

EventExecutorGroup类似于,OrderedMemoryAwareThreadPoolExecutor除了它不强制任何内存约束。您必须实现自己的处理程序来强制执行内存约束 -MemoryAwareThreadPoolExecutor效率不高并且经常出现性能问题。

没有替代品,MemoryAwareThreadPoolExecutor因为 Netty 4 中的所有处理程序方法都是针对同一连接按顺序调用的。如果您想要无序执行,则必须将任务交给java.util.concurrent.Executor. 这个决定是有意的 - 否则处理程序实现不能对线程安全进行任何消耗。

于 2013-04-17T08:25:23.850 回答