EventLoop#submit() vs #execute() vs Channel#writeAndFlush()

149 views Asked by At

What's the difference between the 3 methods when writing bytes to a channel?

In my case, the thread writing these bytes is not the thread that belongs to the channel's EventLoop, and I understand that IO events always happen on the channel's assigned EventLoop thread.

I am trying to minimize latency with getting these bytes flushed as soon as possible. To better understand what I can do to optimize this, I need to know the difference between these 3 ways to write data to a channel, and possibly any other way I may have missed?

byte[] data = ...
Channel channel = ...
// 1
channel.eventLoop().submit(() -> channel.writeAndFlush(data));

// 2
channel.eventLoop().execute(() -> channel.writeAndFlush(data));

// 3
channel.writeAndFlush(data);
1

There are 1 answers

2
Norman Maurer On BEST ANSWER

So for what you are doing here there isn't really much difference except in how the return value of writeAndFlush is propagated.