0
我誤解了DefaultEventExecutorGroup的角色或設置。適用於Netty 4.0中的DefaultEventExecutorGroup的設置
我有一個處理程序:
HandlerClass:
public RequestEventHandler extends LongDelayThreadCapable
private final static int SLEEP_IN_SECONDS = 10;
public RequestEventHandler()
{
super(ConfigurationRequestEventHandler.supportedEvent);
}
@Override
public void userEventTriggered(final ConfigurationRequestEvent event) throws Exception
{
System.out.println("CONFIGURATION REQUEST @ " + new Date());
// Simulate a long query to a legacy JDBC connection
Thread.sleep(ConfigurationRequestEventHandler.SLEEP_IN_SECONDS * 1000);
System.out.println("CONFIGURATION ANSWER @ " + new Date());
}
我添加到管道,像這樣:
管道此外:
public SetupTest(final List<ChannelHandler> channelHandlers)
{
super();
handlers = channelHandlers;
executorGroup = new DefaultEventExecutorGroup(Constants.EXECUTOR_THREADS);
}
public void initChannel(final ChannelPipeline pipeline) throws Exception
{
Assert.notNull(pipeline, "Pipeline must not be null");
if (handlers != null)
{
for (final ChannelHandler h : handlers)
{
if (h instanceof LongDelayThreadCapable)
{
pipeline.addLast(executorGroup, h.getClass().getSimpleName(), h);
}
else
{
pipeline.addLast(h);
}
}
}
}
我的期望是,如果三個事件都來快速連續的事件將被異步處理,隨後該過程的輸出是:
run
CONFIGURATION REQUEST @ [date]
CONFIGURATION REQUEST @ [date]
CONFIGURATION REQUEST @ [date]
CONFIGURATION ANSWER
CONFIGURATION ANSWER
CONFIGURATION ANSWER
而是輸出指示串行處理:
run
CONFIGURATION REQUEST @ [date]
CONFIGURATION ANSWER
CONFIGURATION REQUEST @ [date]
CONFIGURATION ANSWER
CONFIGURATION REQUEST @ [date]
CONFIGURATION ANSWER
我已經看到了一些討論的帖子,並且聲明瞭Netty 4.0將始終使用單個線程。這似乎與這個EventGroup的想法相矛盾。
是否可以同時進行多個長查詢?如果是這樣,我們如何將各個部分連接起來以提供此功能?
因此,在DefaultEventExecutorGroup中分配的多個線程真正說出多少個快速的繼承呼叫可以從多個渠道進入。所以如果有10個頻道有類似的請求進來,那麼它們將被異步處理。但是當事件全部發生在同一個頻道時,它們將被連續處理以保持正確的順序。是? – 2014-09-10 13:30:02
是的,這正是發生的事情 – 2014-09-10 18:28:41