InterruptedExceptions should never be ignored in the code, and simply logging the exception counts in this case as "ignoring".
Instead, InterruptedExceptions should either be rethrown - immediately or after cleaning up the method's state - or the method should be
reinterrupted. Any other course of action risks delaying thread shutdown and loses the information that the thread was interrupted - probably without
finishing its task.
public void run () {
try {
while (true) {
// do stuff
}
}catch (InterruptedException e) { // Noncompliant; logging is not enough
LOGGER.log(Level.WARN, "Interrupted!", e);
}
}
public void run () {
try {
while (true) {
// do stuff
}
}catch (InterruptedException e) {
LOGGER.log(Level.WARN, "Interrupted!", e);
// clean up state...
Thread.currentThread().interrupt();
}
}