public synchronized int select(int interestOps, Integer timeout) {
    int n;
    Selector selector;
    if ((interestOps & SelectionKey.OP_READ) != 0) {
      selector = readSelector;
    } else {
      selector = writeSelector;
    }
    selector.selectedKeys().clear();
    try {
      if (timeout == null) {
        n = selector.select();
      } else {
        int tv = timeout.intValue();
        switch(tv) {
        case 0:
          n = selector.selectNow();
          break;
        default:
          n = selector.select((long)tv);
          break;
        }
      }
    } catch(IOException e) {
      throw new SystemException(e.toString());
    }
    return n;
  }