...
A boolean
flag can be used (as described earlier) if additional clean-up operations need to be performed. When performing asynchronous I/O, a java.nio.channels.Selector
may also be brought out of the blocked state by either invoking its close()
or wakeup()
method.
Compliant Solution (interruptible channel)
...
This method interrupts the current thread, however, it only stops the thread because the thread logic polls the interrupted flag using the method Thread.interrupted()
, and shuts down when it is interrupted. Invoking the interrupt()
method of a thread that is blocked because of a java.nio.channels.Selector
also causes the thread to awaken.
Noncompliant Code Example (database connection)
...