Re: SocketChannels NIO



Stefan Schulz wrote:
I am not entirely sure about this, but i think you need to keep your
channel in nonblocking mode as long as it is registered with a
selector. However, if this really is your bottleneck, you can have one
(or several) threads on standbye, which get handed a channel once it
becomes readable, read as much data as possible, and then return to
standbye mode.

One way of handling this is to copy from the channel into a PipedOutputStream (or saner equivalent) in your main selector handling thread. Then have worker thread work as traditional on the matching InputStream.


This can be particularly effective with tasks such as web serving. Connections will be idle most of the time. However bursts of activity occur where traditional I/O may be significantly simpler.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
.



Relevant Pages

  • Re: SocketChannels NIO
    ... which get handed a channel once it ... standbye mode. ... Prev by Date: ...
    (comp.lang.java.programmer)
  • Re: NIO and accepts()
    ... > assume that connections will not last long specially with lossy web ... >>multiple threads selecting on the same selector concurrently, ... I believe that socket acceptance ... SelectionKey, retrieve the channel, perform as much of the required ...
    (comp.lang.java.programmer)
  • Re: NIO and accepts()
    ... My goal is to write the best ECHO server for various platforms (Java, ... > multiple threads selecting on the same selector concurrently, ... read has finished and issues a send request on the received buffer. ... The threads that perform Channel registrations also call select. ...
    (comp.lang.java.programmer)
  • DatagramChannel.receive()
    ... I use a selector to manage the unblocking DatagramChannel, ... When I got the event that I can read from the channel ... ByteBuffer buffer = ByteBuffer ... int port = sock.getPort; ...
    (comp.lang.java.programmer)
  • Re: Switching from Non-Blocking to Blocking IO
    ... Try waking up the selector immediately you deregister the channel. ... Make sure the selector loop copes correctly with zero ready channels. ... It must have been in response to an OP_READ originally, which must have been processed in the selector thread, so the deregister and switch to blocking mode should have been done there, then you wouldn't have a problem. ...
    (comp.lang.java.programmer)