Should we set the interrupted flag when catching an InterruptedException
inside a task managed by an ExecutorService
? Or should we just swallow the InterruptedException
?
Example:
final ExecutorService service = ...;
final Object object = ...;
service.submit(() -> {
try {
while (!condition) {
object.wait();
}
} catch (final InterruptedException exception) {
Thread.currentThread().interrupt(); // yes or no?
}
});
ExecutorService
, what is the difference between swalling and not swalling the exception? How does theExecutorService
behaves in both cases? – Leukoderma