Why channel.write blocked if I block messageReceived on same channel?

tsuna tsunanet at gmail.com
Thu Aug 19 12:45:45 EDT 2010


On Thu, Aug 19, 2010 at 9:15 AM, man4j <man4j at ya.ru> wrote:
> 1. If I block in method messageReceived (f.e. Thread.sleep or breakpoint)
> then channel.write(in separate thread) only put data in queue, but not send
> via socket until messageReceived still blocked. Why?

I *think* it's because when you call channel.write() it will attempt
to send a message downstream through the channel's ChannelPipeline.
But the ChannelPipeline is already "busy" in messageRecevied.  And a
ChannelPipeline is only active in one thread at a time (by default).
So Netty has to wait until messageReceived gets unblocked and
completes before it can process the downstream message you wrote with
channel.write().
Normally you're not supposed to block in messageReceived.

> 2. channel.write is thread-safe?

Yes.

-- 
Benoit "tsuna" Sigoure
Software Engineer @ www.StumbleUpon.com


More information about the netty-users mailing list