title: Java Selector NIO Reading problem
body: <p>Relevant Code
  -- Note Instructions is merely a class with several methods which will operate on the data. A new thread is created operate on the data read.</p>
  
  <p>READ THREAD:</p>
  
  <pre><code>while(true) {
       System.out.println(".");
       if(selector.select(500) == 0)
            continue;
  
       System.out.println("processing read");
  
       for(SelectionKey sk : selector.keys()) {
            Instructions ins = myHashTable.get(sk);
            if(ins == null) { 
                 myHashTable.put(sk, new Instructions(sk));
                 ins = myHashTable.get(sk);
            }
            ins.readChannel();
       }
  }
  </code></pre>
  
  <p>READCHANNEL</p>
  
  <pre><code>public void readChannel() {
       BufferedReader reader = new BufferedReader(Channels.newReader((ReadableByteChannel) this.myKey.channel(), "UTF-8"));
       Worker w = new Worker(this, reader.readLine());
       (new Thread(w)).start();
  }
  </code></pre>
  
  <p>The new thread then calls more <code>Instructions</code> methods.</p>
  
  <p>When the ins function finishes it <em>might</em> write to a Writer:</p>
  
  <pre><code>Writer out = Channels.newWriter((WritableByteChannel) key.channel(), "UTF-8");
  out.write(output);
  out.flush();
  </code></pre>
  
  <p>I can confirm that my client (a flash movie), then receives and acts on the output.</p>
  
  <p>Finally, <code>w</code> exits.</p>
  
  <p>After the receipt of the first message from the client, and successful processing, however, no more messages are taken care of by the <code>READ THREAD</code> loop. I believe the key is registered with the selector and ready to read. I have checked by looping on all the keys to see if they are readable with isReadable &amp; isRegistered on the channel and the result is true in all cases to date. When a second message is sent from the client, however, the only response I see in the read thread is that the '.' character is printed out not every half second, but continuously faster. I believe, then, that the data is there in the channel, but for some reason the Selector isn't selecting any key.</p>
  
  <p>Can anyone help me?</p>