【问题标题】:Netty4 Unexpected exception in the selector loopNetty4 选择器循环中的意外异常
【发布时间】:2013-06-26 02:48:07
【问题描述】:

我已经使用 Netty4.0.0.CR3 实现了一个 HTTP 客户端。我正在管理一个与服务器的客户端连接池,基于某个事件,事件处理程序线程从池中选择一个连接,将 HTTP 请求发送到服务器,等待响应 (FullHttpResponse),然后将连接释放回池。

现在我面临的问题是,在重负载下,我的日志中出现了这些warnings, `

15:56:59.828 nioEventLoopGroup-37-1 WARN i.n.c.nio.NioEventLoop - Slf4JLogger.warn() :选择器循环中的意外异常。 java.util.concurrent.RejectedExecutionException:事件执行器 终止于 io.netty.util.concurrent.SingleThreadEventExecutor.reject(SingleThreadEventExecutor.java:711) ~[netty-all-4.0.0.CR3.jar:na] 在 io.netty.util.concurrent.SingleThreadEventExecutor.addTask(SingleThreadEventExecutor.java:306) ~[netty-all-4.0.0.CR3.jar:na] 在 io.netty.util.concurrent.SingleThreadEventExecutor.execute(SingleThreadEventExecutor.java:696) ~[netty-all-4.0.0.CR3.jar:na] 在 io.netty.channel.AbstractChannel$AbstractUnsafe.invokeLater(AbstractChannel.java:968) ~[netty-all-4.0.0.CR3.jar:na] 在 io.netty.channel.AbstractChannel$AbstractUnsafe.close(AbstractChannel.java:750) ~[netty-all-4.0.0.CR3.jar:na] 在 io.netty.channel.nio.NioEventLoop.closeAll(NioEventLoop.java:521) ~[netty-all-4.0.0.CR3.jar:na] 在 io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:329) ~[netty-all-4.0.0.CR3.jar:na] 在 io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:114) [netty-all-4.0.0.CR3.jar:na] 在 java.lang.Thread.run(Thread.java:680) [na:1.6.0_45]

`
现在,我想问的是,这些警告是否会产生任何问题,如果是的话,有任何关于如何解决这个问题的指示,或者我可以忽略它们。

问候!!

【问题讨论】:

    标签: java netty


    【解决方案1】:

    我认为您在处理所有请求之前关闭了 EventLoopGroup。请务必使用 EventLoopGroup.shutdownGracefully()。

    如果你在处理完所有事情之前关闭 EventLoopGroup 会产生这样的错误

    【讨论】:

    • 感谢您的回复。我没有调用 EventLoopGroup.shutdown(),而是在我的客户端中调用channel.closeFuture();,然后调用bootstrap.shutdown(); 来清除与服务器的连接。这是正确的方法吗?还是我应该做不同的事情
    • 调用 EventLoopGroup.shutdownGracefully()
    • 非常感谢。还有一个查询,我正在使用 apache commons pool,创建多个指向服务器的 http 连接,并为每个客户端使用一个公共 (NioEventLoopGroup)。现在,如果连接已关闭,我该如何进行清理,因为我只在池关闭时调用 EventLoopGroup.shutdownGracefully()。如何管理单个连接清理。
    • 连接清理是什么意思?
    • Http-server 关闭连接,或者没有活动空闲连接需要释放,根据池配置。对于此类连接,需要进行任何特定的清理。
    猜你喜欢
    • 2017-10-18
    • 1970-01-01
    • 2021-02-16
    • 1970-01-01
    • 1970-01-01
    • 2014-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多