When i have a selector.select() registered to a SocketChannel, and i close the SocketChannel's peer in a separate thread, selector.select() returns, and that channel's READ operation is set. If i have a ServerSocketChannel registered to the selector, and i close the ServerSocketChannel, selector.select() does not return. Is there anyway i can detect that the ServerSocketChannel was closed while being blocked in selector.select()?
I tried using selector.wakeup(), and going through the set of keys (not selected keys), and seeing if there are any unopened channels in the set, but as soon as the close is done on the ServerSocketChannel, it is deregistered from selector, so it is not in the select.keys() set.