Write ordering

32 views
Skip to first unread message

Pei Sun

unread,
Dec 12, 2016, 8:35:55 AM12/12/16
to ne...@googlegroups.com
Hi Netty-users and experts,
    I have a question about the write ordering in netty.

// The following all happens in one thread.
channel.writeAndFlush(msg1);
channel.writeAndFlush(msg2);

Is it guaranteed that msg2 will be written after msg1? 

4.0 release notes mentioned about this and stated that the ordering are not well-defined if we mix event-loop thread and other threads. But what if I all invoke the writeAndFlush in one thread (not the event-loop thread)?

What if I do the following in one thread?

channel.eventloop().submit(new runnable() {
   public void run() {channel.writeAndFlush(msg1);}
}
channel.eventloop().submit(new runnable() {
   public void run() {channel.writeAndFlush(msg2);}
}

Thanks a lot.

Pei Sun

Norman Maurer

unread,
Dec 12, 2016, 8:36:51 AM12/12/16
to ne...@googlegroups.com
On 12 Dec 2016, at 08:23, Pei Sun <peisu...@gmail.com> wrote:

Hi Netty-users and experts,
    I have a question about the write ordering in netty.

// The following all happens in one thread.
channel.writeAndFlush(msg1);
channel.writeAndFlush(msg2);

Is it guaranteed that msg2 will be written after msg1? 

Yes it is.


4.0 release notes mentioned about this and stated that the ordering are not well-defined if we mix event-loop thread and other threads. But what if I all invoke the writeAndFlush in one thread (not the event-loop thread)?

What if I do the following in one thread?

channel.eventloop().submit(new runnable() {
   public void run() {channel.writeAndFlush(msg1);}
}
channel.eventloop().submit(new runnable() {
   public void run() {channel.writeAndFlush(msg2);}
}


This will still run in the Eventloop thread.


Thanks a lot.

Pei Sun


--
You received this message because you are subscribed to the Google Groups "Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netty+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netty/CAKrkhguV%2B7T97rd_0CiPZX1fwP2kMJuX2kbbzK6pohw3pJT74g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

pe...@alluxio.com

unread,
Dec 12, 2016, 1:18:44 PM12/12/16
to Netty discussions
Thank you, Norman.
Reply all
Reply to author
Forward
0 new messages