0

Is there need to do further cleanup after closing a socket channel if the channel was used with a selector and the selector is still being used?

traveh
  • 2,700
  • 3
  • 27
  • 44

1 Answers1

2

No. Closing the channel cancels the selection key. It will be removed from the key set on the next select().

However, when the current select() returns, it is possible for a cancelled key to be in the selected-keys set, which you can detect via SelectionKey.isValid(), as seen in any decent NIO select loop example.

user207421
  • 305,947
  • 44
  • 307
  • 483