当在由ExecutorService
管理的任务中捕获InterruptedException
时,我们是否应该设置中断标志?还是应该直接忽略InterruptedException
?
示例:
final ExecutorService service = ...;
final Object object = ...;
service.submit(() -> {
try {
while (!condition) {
object.wait();
}
} catch (final InterruptedException exception) {
Thread.currentThread().interrupt(); // yes or no?
}
});
ExecutorService
中,吞掉异常和不吞掉异常有什么区别?在这两种情况下,ExecutorService
的行为如何? - user4460845