gpt4 book ai didi

java - 在没有 ChannelFuture 的情况下写入 Netty channel

转载 作者:搜寻专家 更新时间:2023-11-01 01:46:24 24 4
gpt4 key购买 nike

是否可以在不创建不必要的 ChannelFuture 的情况下写入 Netty channel ? (不为 GC 生成不必要的对象...)

最佳答案

如果你真的不想创建一个ChannelFuture,你可以为 Netty 3 做这个:

Channels.write(ctx, Channels.succeededFuture(channel), message);

Channels.succeededFuture(..) 返回一个 channel 本地单例对象。但是,您永远不应向返回的 future 添加监听器,因为它已经完成。

在 Netty 4 中,你可以使用 void promise:

ctx.write(msg, ctx.voidPromise());

ChannelHandlerContext.voidPromise() 返回一个永远不会实现的虚拟单例 promise 。添加监听器或等待它完成的操作将立即失败。

关于java - 在没有 ChannelFuture 的情况下写入 Netty channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8960416/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com