I've recently discovered two utilities in Guava that are very useful in combating InterruptedExceptions that contaminate business logic of code:
- Uninterruptibles: https://google.github.io/guava/releases/21.0/api/docs/com/google/common/util/concurrent/Uninterruptibles.html. It has methods that substitute typical interruptible blocking code with a loop that ignores an InterruptedException, as recommended in the "Java Concurrency in Practice" book. It's recommended to try to resort to this utility when you don't expect interruption or don't want to deal with it and do something like wrapping into a RuntimeException or logging to get rid of it. Futures.getUnchecked(): https://google.github.io/guava/releases/21.0/api/docs/com/google/common/util/concurrent/Futures.html#getUnchecked-java.util.concurrent.Future- similar to Uninterruptibles, but additionally "washes" a Future.get() call off ExecutionException and a CancellationException.