java socket i/o with callback/non-blocking



I have the O'Reilly Book Java NIO (with the mouse on it) and I'm trying
to figure out how to do non-blocking socket i/o. Basically I want to
have some subroutine to be called whenever there is data available to
read on a socket object without having to poll it. I'm having trouble
understanding how to do this in Java and the NIO book isn't really
helpful in that regard. Right now the way I have my program written is
that I spawn a separate thread that has a while loop that checks the
socket for data and then goes to sleep for a while but that doesn't
seem like a very efficient implementation. I'm having trouble finding
much information on NIO, especially tutorials and code samples that
deal with this.

.



Relevant Pages

  • Re: Scatter/Gather in Java or Javascript & html (Dynamic class loading?)
    ... constrained by the requirement to talk to a non-Java server here. ... FWIW here are my thought processes whilst deciding which Java socket client ... The only problem I saw with NIO is that Esmond has said "For example, ...
    (comp.lang.java.programmer)
  • Re: Available memory and limit on thread creation
    ... >> that would allow you to use NIO to multiplex monitoring of the state ... > new, quickly generated, connect attempt, and another socket to service, ... contending for CPU time. ... thus requiring fewer threads and possibly yielding a ...
    (comp.lang.java.programmer)
  • Re: Communicating with a servlet using NIO?
    ... I suppose you could use the Socket class instead of URLConnection, but the value of a channel on the client side is questionable. ... The point of NIO is to multiplex several communications going through the same port. ... Why not just use the regular IO operations through the URLConnection and just let the server do the NIO for its own sake? ...
    (comp.lang.java.programmer)
  • Re: Establishing Socket Connection to a slow or busy server
    ... The big problem using the standard Socket classes up until jdk 1.3 is ... jdk 1.4 added the nio classes which perform much ... the connection, but then it is no longer asynchronous/non-blocking. ... See my post on this group about nio and timeouts. ...
    (comp.lang.java.programmer)