1
在我的Netty SimpleChannelUpstreamHandler
当我收到消息时,我需要启动到另一个Netty服务器的连接并转发消息。然而,启动第二个连接时使用:SimpleChannelUpstreamHandler在I/O线程中等待*()导致死锁
ChannelFuture channelFuture = clientBootstrap.connect(new InetSocketAddress(host, port));
hannelFuture.awaitUninterruptibly();
这将导致以下错误:
java.lang.IllegalStateException: await*() in I/O thread causes a dead lock or sudden performance drop. Use addListener() instead or call await*() from a different thread.
at org.jboss.netty.channel.DefaultChannelFuture.checkDeadLock(DefaultChannelFuture.java:314)
at org.jboss.netty.channel.DefaultChannelFuture.awaitUninterruptibly(DefaultChannelFuture.java:226)
at com.my.NettyClient.start(NettyClient.java:204)
....
at com.my.MyChannelUpstreamHandler.messageReceived(MyChannelUpstreamHandler.java:52)
请告诉我该开始第二个连接的最佳方式?我应该做以下事情吗?:
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.submit(new Runnable() {
@Override
public void run() {
// Connect to another Netty Server...
// Forward on message...
}
});
executorService.shutdown();
...
这是浪费,开始每个消息收到新消息的线程?
链接似乎有所改变。这是一个[已更新的](http://static.netty.io/3.6/xref/org/jboss/netty/example/proxy/HexDumpProxyInboundHandler.html) – omerkudat