Netty ClosedChannelException当异步处理我收到的消息时

时间:2012-05-04 07:55:44

标签: netty

当我收到新请求时,我会将此MessageEvent放入LinkedBlockingQueue; 另一个线程正在运行以从MessageEvent读取LinkedBlockingQueue,因此我处理messageEvent并写入客户端。但是当我写入客户端时,会发生异常。

这是我的代码:

@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
    LogConsole.info(e.toString());
    messageReceivedQueue.addReceivedMessage(e);
}

public void run() {
   MessageEvent  e = messageReceivedQueue.get();       
   e.getChannel().write(e.getMessage());
}

以下是我得到的错误:

java.nio.channels.ClosedChannelException
    at org.jboss.netty.channel.socket.nio.NioWorker.cleanUpWriteBuffer(NioWorker.java:645)
    at org.jboss.netty.channel.socket.nio.NioWorker.writeFromUserCode(NioWorker.java:372)
    at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.handleAcceptedSocket(NioServerSocketPipelineSink.java:137)
    at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.eventSunk(NioServerSocketPipelineSink.java:76)
    at org.jboss.netty.channel.Channels.write(Channels.java:632)
    at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:70)
    at org.jboss.netty.channel.Channels.write(Channels.java:611)
    at org.jboss.netty.channel.Channels.write(Channels.java:578)
    at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:251)
    at com.bankht.cis.tcs.service.executor.adapter.AbstractMessageAdapter$ProcessWorker.run(AbstractMessageAdapter.java:97)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

1 个答案:

答案 0 :(得分:0)

这告诉您通道在此期间已关闭。您无能为力,因为客户端可能会一直关闭套接字。