netty - 如何在 Netty 4 中删除拥塞的连接

标签 netty

使用 Netty 4,如何检测我写入的数据在我的连接端被堵塞,并在远程端无法跟上时关闭连接?

我正在检查是否

ChannelHandlerContext.channel.outboundByteBuffer.readableBytes > MaxWriteBuffer

但在最新的 Netty 4 版本中,这给了我一个异常(exception):

java.lang.IllegalStateException: nextOutboundByteBuffer() called from outside the eventLoop

最佳答案

您需要从 EventLoop 执行此操作,否则它不是线程安全的。

所以像这样:

ChannelHandlerContext ctx = ....
final Channel channel = ctx.channel();
channel.eventLoop().execute(new Runnable() {
    public void run() {
        if (channel.outboundByteBuffer.readableBytes() > MaxWriteBuffer) {
            // do something
        }
    }
});

关于netty - 如何在 Netty 4 中删除拥塞的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16368572/

相关文章:

java - netty中如何动态管理CPU负载?

java - 在 Netty 中禁用 HTTP 协议(protocol)请求?

java - 如何在 Netty 客户端 (4.1) 中使用 Socks4/5 代理处理程序

java - netty - 我可以引导一个新客户端来连接 channel 处理程序中的其他服务器吗?

http - javax.net.ssl.SSLException : Inbound closed before receiving peer's close_notify: possible truncation attack?

java - LEAK : ByteBuf. release() 在被垃圾收集之前未被调用

spring - 用于嵌入式套接字监听器的 Netty/Grails Web 集成

java - NoClassDefFoundError : io/netty/util/Timer

java - 何时使用多个主要方法?

netty - 使用 vertx web 客户端版本 4.0.0 时出现 java.lang.IllegalAccessError