private int doCancel(){
  int deselected=0;
  Set<SelectionKey> cancelledKeys=cancelledKeys();
synchronized (cancelledKeys) {
    if (cancelledKeys.size() > 0) {
      for (      SelectionKey currentKey : cancelledKeys) {
        mutableKeys.remove(currentKey);
        deregister((AbstractSelectionKey)currentKey);
        if (mutableSelectedKeys.remove(currentKey)) {
          deselected++;
        }
      }
      cancelledKeys.clear();
    }
  }
  return deselected;
}

private int doCancel ( ) { int deselected = 0 ; Set < SelectionKey > cancelledKeys = cancelledKeys ( ) ; synchronized ( cancelledKeys ) { if ( cancelledKeys . size ( ) > 0 ) { for ( SelectionKey currentKey : cancelledKeys ) { mutableKeys . remove ( currentKey ) ; deregister ( ( AbstractSelectionKey ) currentKey ) ; if ( mutableSelectedKeys . remove ( currentKey ) ) { deselected ++ ; } } cancelledKeys . clear ( ) ; } } return deselected ; }
removes cancelled keys from the key set and selected key set , and unregisters the corresponding channels . returns the number of keys removed from the selected key set .
