是否可以在不创建不必要的 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/