Ensure that a task is interruptible
How to ensure that my tasks are responsive to interruption when I call
Future.cancel()?
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Boolean> future = executor.submit(task);
try {
future.get(timeout, timeoutUnit);
} catch (TimeoutException e) {
future.cancel(true);
}
No comments:
Post a Comment