ChannelOutboundInvoker.flush() 是同步/阻塞调用吗?
Is ChannelOutboundInvoker.flush() a synchronous / blocking call?
在调用 ChannelOutboundInvoker.flush()
或 ChannelOutboundInvoker.writeAndFlush()
后直接重用(由其包装的字节数组)ByteBuf 是否安全?
byte[] bytes = ...
ByteBuf byteBuf = Unpooled.wrappedBuffer(bytes);
ctx.writeAndFlush(byteBuf);
bytes[0] = 0; // safe to do here?
我已经试了几十次了,每次都很好,但我想知道是否保证可以。
不,这不安全/没问题,因为不能保证立即执行。执行此操作的唯一“安全”方法是在 ChannelFuture
完成后重新使用 byte[]
writeAndFlush(...)
.
像这样:
byte[] bytes = ...
ByteBuf byteBuf = Unpooled.wrappedBuffer(bytes);
ctx.writeAndFlush(byteBuf).addListener(f -> {
bytes[0] = 0;
});
在调用 ChannelOutboundInvoker.flush()
或 ChannelOutboundInvoker.writeAndFlush()
后直接重用(由其包装的字节数组)ByteBuf 是否安全?
byte[] bytes = ...
ByteBuf byteBuf = Unpooled.wrappedBuffer(bytes);
ctx.writeAndFlush(byteBuf);
bytes[0] = 0; // safe to do here?
我已经试了几十次了,每次都很好,但我想知道是否保证可以。
不,这不安全/没问题,因为不能保证立即执行。执行此操作的唯一“安全”方法是在 ChannelFuture
完成后重新使用 byte[]
writeAndFlush(...)
.
像这样:
byte[] bytes = ...
ByteBuf byteBuf = Unpooled.wrappedBuffer(bytes);
ctx.writeAndFlush(byteBuf).addListener(f -> {
bytes[0] = 0;
});