我正在使用FixedChannelPool来获取频道作为httpClient,而程序将在大约10秒钟后抛出java.io.IOException: An established connection was aborted by the software in your host machine
。似乎远程tomcat服务器关闭了空闲的tcp连接,但是我该如何处理呢?
这是针对我的Windows系统中的Java8和Netty 4.16的。开始时没有发生异常,但是大约10秒钟或更长时间后出现了异常。
我的代码是这样的,通道将在处理程序中释放。
Future<Channel> future = pool.acquire();
future.addListener(new FutureListener<Channel>() {
@Override
public void operationComplete(Future<Channel> future) throws Exception {
//send msg to server
Channel channel = future.getNow();
if (channel.isActive()&&channel.isWritable()) {
System.out.println("chanelId:>>>>>>>" + channel.id() + " requestId:>>>>>>>" + hRequest.getRequestId());
setAttr(hRequest, channel, defaultFuture, pool);
setCallBack(channel, callback);
channel.writeAndFlush(hRequest.getRequest());
} else {
System.out.println("channelInactive>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + inactiveNums.incrementAndGet());
}
}
});
该异常的详细信息如下:
[nioEventLoopGroup-2-1]警告io.netty.channel.DefaultChannelPipeline-触发了exceptionCaught()事件,该事件到达管道的末尾。通常,这意味着管道中的最后一个处理程序未处理异常。
java.io.IOException: An established connection was aborted by the software in your host machine。
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:192)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)
at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288)
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1125)
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:347)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:682)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:617)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:534)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:906)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)