如何确保我的任务在我打电话时对中断做出响应Future.cancel()
?
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Boolean> future = executor.submit(task);
try {
future.get(timeout, timeoutUnit);
} catch (TimeoutException e) {
future.cancel(true);
}