title: Why iterate SelectionKey with iterator.remove() in Java NIO Selector
body: <p>Following code cut from HBase RpcServer.java. I can't understand that remove SelectionKey in each time of loop.Are there some reasons in here?Is it a optimizing?</p>
  
  <pre><code>      try {
        selector.select();
  
        Iterator&lt;SelectionKey&gt; it = selector.selectedKeys().iterator();
  
        while (it.hasNext()) {
          SelectionKey key = it.next();
          it.remove();
          if (key.isValid()) {
            if (key.isReadable()) {
              doRead(key);
            }
          }
        }
  
      } catch (IOException e) {
        LOG.warn("Run into IOExpection in " + name, e);
      }
  </code></pre>