Channels and Selectors. That covers a lot of territory. First of all, let me point out that the Selectors chapter of my book is available online from
O'Reilly's site.
Channels: The notion of a channel is new with NIO. It's essentially a new metaphor that represents a pathway to an I/O service of some kind.
Traditional Java I/O is based on the stream, or pipeline, metaphor where data flows in one end and out the other. With a stream, there are no structural boundaries within the data and the stream may be unbounded.
Streams are a very useful metaphor but not all I/O fits that mold. There is also the concept of block-oriented I/O - most commonly associated with disk files. Most OSs operate most efficiently on blocks which are multiples of the virtual memory page size.
There are also some common I/O operations which don't involve any data transfer at all - such as obtaining a file lock for example.
A channel is a nexus, or connection, to some I/O service such as a socket or file. Channels transfer data to or from buffers which are containers for blocks of data. There are no API calls to read or write individual bytes with channels.
Some channels (specifically socket channels for now) may be placed in non-blocking mode. This allows a thread to poll a socket to see if data is available on it but never get blocked if the socket is empty. Non-blocking mode enables polling, but polling can be wasteful if you have lots of sockets.
Selectors: The Selector class performs a very useful function -
readiness selection. This means that a Selector can examine a large number of sockets and
select the subset of those which are currently
ready. This means you don't need to waste time polling empty sockets, you can be notified when new data arrives, which is what you want to know. You save a lot of fruitless effort if you don't need to poll idle socket connections.
That's a sort of whirlwind summary of channels and selectors. If you have further specific questions, please post them.
[ April 17, 2003: Message edited by: Ron Hitchens ]
[ April 17, 2003: Message edited by: Ron Hitchens ]