【问题标题】:Order of multiple Channel#write多个通道的顺序#write
【发布时间】:2014-03-07 06:47:09
【问题描述】:

我正在阅读 Netty 频道的 Javadoc:http://netty.io/4.0/api/io/netty/channel/Channel.html

在我的单线程中(在Netty的IO线程之外),如果我多次调用Channel#write

channel.write(msg1);
channel.write(msg2);
channel.write(msg3);

Netty 是否会确保消息按顺序输出:msg1、msg2、msg3? 还是我必须自己手动确保订单(非常繁琐,非常丑陋)?

ChannelFuture f1 = channel.write(msg1);
f1.addListener(new ChannelFutureListener() {
  public void operationComplete(ChannelFuture future) {
    ChannelFuture f2 = channel.write(msg2);
    f2.addListener(new ChannelFutureListener() {
      public void operationComplete(ChannelFuture future) {
        channel.write(msg3);
      }
    });
  }
});

【问题讨论】:

    标签: netty


    【解决方案1】:

    答案是肯定的

    Channel 是线程安全的,这意味着从不同的地方对其进行操作是安全的 线程。此外,此方法保证消息的写入顺序与您传递的顺序相同 将它们写入 write 方法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-30
      • 2018-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-22
      • 2014-11-09
      相关资源
      最近更新 更多