Fast question about threading inside Netty

Marzullo coder82 at gmail.com
Tue Mar 23 07:46:25 EDT 2010


You know, I wrote such question after I've read about boss thread and worker
thread in case of NIO socket and OIO socket, if you look up the doc, it
gives the idea. The point is:

OIO socket:
Boss thread accepts for connections, when connection is accepted (3 way
handshake completed in case of TCP), it creates a channel which represents
the accepted connection itself. This channel is handed to a worker thread
(often referred as I/O thread) got from thread pool. On such threads, I/O
operations are blocking. If you ever implemented a server in C, this is very
similar, if not equal to, 1-accepting a socket then 2-create a thread and
3-hand socket descriptor to such thread which will block on reads and
writes, that's it.
So here the important difference is that you have one accepted channel per
I/O thread and every I/O operation within such thread is blocking.

NIO socket:
Similar to above, boss thread accepts connection, create channel for such
connection and hands it to worker thread. The difference is here, you can
have more than one channel handed to worker thread, then of course I/O must
be non blocking otherwise by blocking on one channel you'd starve the
others...
So here is the point when I read on the docs:

"If await()  is called by an event handler method, which is called by the
I/O thread, the I/O operation it is waiting for might never be complete
because await()  can block the I/O operation it is waiting for, which is a
dead lock. "

so if you wait withing such worker thread (I/O thread) you might
starve/lower responsiveness on other channels or even cause deadlock
depending on what you actually do.

It'd be nice to have clarifications from T. Lee about all this.
Thanks.

-- 
View this message in context: http://n2.nabble.com/Fast-question-about-threading-inside-Netty-tp4765193p4783431.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list