Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Please the arthur of Java NIO talk about the Select and Channel  RSS feed

 
Jack Yang
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In NIO,the Select and Channel are new things,please explain more details and how to use.
thanks
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jack,
I believe you will find ample explanation in one (or more) of the following resources -- assuming you haven't already seen them, of-course ;-)
1. Dick Baldwin's Java Tutorials
http://www.dickbaldwin.com/tocadv.htm
(Look for the section entitled, "New features in V1.4" -- lesson 1780)

2. As a member of JavaLobby.org (membership is free), you can download a PDF version of the book JDK 1.4 Tutorial. The first two chapters deal with NIO.
http://javalobby.org/members/index.jsp

3. The Java Developer Connection (JDC) has two "technical" articles about NIO:
http://access1.sun.com/techarticles/CharBasedIO/CharBasedIO.html
http://developer.java.sun.com/developer/technicalArticles/releases/nio/

3. The Java Developer's Almanac has examples for every class and package in JDK 1.4, including NIO:
http://javaalmanac.com/egs/java.nio/pkg.html

4. The javadoc for JDK 1.4 also has _lots_ of information:
http://java.sun.com/j2se/1.4.1/docs/guide/nio/index.html
Hope this has helped you.
Good Luck,
Avi.
 
Ron Hitchens
Author
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!