我们使用 ScheduledThreadPoolExecutor 并在提交作业后立即调用shutdown。因为根据文档 Shutdown 不会杀死提交的任务,正在运行的任务并允许它完成。
问题是shutdown后我们能不能继续使用ScheduledThreadPoolExecutor提交返回的future对象。
私有静态未来 submitACall(Callable callableDelegate) {
ScheduledThreadPoolExecutor threadPoolExe = null;
尝试 {
threadPoolExe = new ScheduledThreadPoolExecutor(1);
返回 threadPoolExe.submit(callableDelegate);
} 最后 {
threadPoolExe.shutdown();
}
}
//在另一个方法中...
如果(未来.isDone())
未来.get();