...
Wiki Markup |
---|
The {{Thread.interrupt()}} method is frequently used to awaken a blocked thread before it can be stopped. It awakens threads that are blocked on {{wait()}} methods of class {{Object}}, and {{join}} and {{sleep}} methods of class {{Thread}}. In these cases, the thread's interrupt status is cleared and it receives an {{InterruptedException}}. If the thread is blocked on I/O operations upon an interruptible channel, the channel is closed, the thread's interrupt status is set and it receives a {{ClosedByInterruptException}}. Similarly, a thread waiting on a selector also returns from the operation with its interrupted status set. \[[API 06|AA. Java References#API 06]\] |
Wiki Markup |
---|
The {{java.lang.ThreadGroup.interrupt()}} is not deprecated and is often seen as an option to interrupt all the threads belonging to a thread group. "This is no guarantee that a program will terminate, however, because libraries that you have used may have created user threads that do not respond to interrupt requests. The AWT graphics library is one well-known example." \[[JPL 06|AA. Java References#JPL 06]\]. Moreover, using the {{ThreadGroup}} API is discouraged (see [CON17-J. Avoid using ThreadGroup APIs]). |
Compliant Solution (1) (volatile
flag)
...