Code example for SelectionKey

Methods: attach, isValid

0
    private void clearSelectionKey() { 
        final Lock lock = this.keyLock;
        lock.lock();
        try { 
            SelectionKey key = this.processKey;
            if (key != null && key.isValid()) {
                key.attach(null);
                key.cancel();
            } 
        } finally { 
            lock.unlock();
        } 
    } 
 
    private boolean closeSocket() { 
        clearSelectionKey(); 
        SocketChannel channel = this.channel;
        if (channel != null) {
            boolean isSocketClosed = true;
            Socket socket = channel.socket();
            if (socket != null) {