//Selector通过select方法通知我们我们感爱好的事件发生了。 nKeys = selector.select(); //假如有我们注册的事情发生了,它的传回值就会大于0 if(nKeys > 0) { debug("NBTest: Number of keys after select Operation: " +nKeys);
//Selector传回一组SelectionKeys //我们从这些key中的channel()方法中取得我们刚刚注册的channel。 Set selectedKeys = selector.selectedKeys(); Iterator i = selectedKeys.iterator(); while(i.hasNext()) { s = (SelectionKey) i.next(); printKeyInfo(s); debug("NBTest: Nr Keys in selector: " +selector.keys().size());