假设我有一个方法如下:
public void poll(Callable<Boolean> callable) {
ScheduledExecutorService service = Executors.newSingleThreadedScheduledExecutor();
Future<Boolean> future = service.schedule(callable, 0L, TimeUnit.MILLISECONDS);
try {
while (!future.get()) {
future = service.schedule(callable, 5L, TimeUnit.MINUTES);
}
} catch (ExecutionException e) {
// ...
} catch (InterruptedException e) {
// ...
} finally {
service.shutdown();
}
}
an 是如何InterruptedException
被抛出(并陷入poll()
)的?可调用对象(包括InterruptedException
,对吗?)抛出的任何东西都会是ExecutionException
,我们永远不会取消任何期货,并且shutdownNow()
永远不会调用服务。
顺便说一句:既然如此,是否有可能使这种轮询方法对诸如此类的事情更加防弹InterruptedException
?