Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This method interrupts the current thread, however, it only stops the thread because the code polls the interrupted flag using the method Thread.interrupted(), and shuts down the thread when it is interrupted. Using a SocketChannel ensures that the condition in the while loop is tested as soon as an interruption is received, despite the read operation being a blocking operation. Invoking the interrupt() method of a thread that is blocked because of a java.nio.channels.Selector also causes the thread to awaken.

...