Blocking behavior differs in NIO client versus server

"이희승 (Trustin Lee)" trustin at gmail.com
Mon Nov 8 23:45:11 EST 2010


The difference is from which thread you call Channel.write().  On the
client side, you are calling it from a user thread.  On the server side,
you are calling it from an I/O thread.  If a blocking operation is
called in an I/O thread, the I/O thread will not perform any I/O until
the blocking operation returns the control to Netty.

HTH

Alex Wang wrote:
> I implmented an NIO client and a server both use a subclass of
> SimpleChannelHandler in the channel pipeline.  The handler is designed to
> handle a synchronous protocol, and as such, the writeRequested() blocks (via
> a BlockingQueue) and only returns when an ACK has been received thru
> messageReceived().  This works fine in the client in that ACKs and other
> messages continue to arrive and come up through the channel while
> writeRequested() blocks, thus successfully removing the block as intended.  
> 
> However, when the same handler is used in a NIO server, the blocking
> writeRequested() seems to lock the handler object and stops both incoming
> and outgoing ACKs and messages, causing the blocking statement to time out. 
> (I know this may not be a good way to handle a synchronous protocol, and I
> have a couple of ideas after reading the "handshake" example. Any comments
> will be greatly appreciated.)  But my question is why this works for the
> client but not for the server?  By the way, I tried inserting an
> ExecutionHandler before the handler in question, but that did not change the
> server's behavior, i.e. incoming ACK got through the lower-level decoder at
> the server channel, but the ACK did not get processed until after the
> blocking statement times out.
> 
> Any help is highly appreciated!
> 
> Thanks,
> Alex
> 

-- 
Trustin Lee - http://gleamynode.net/


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 290 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20101109/632a355b/attachment.bin 


More information about the netty-users mailing list