0
我们使用ScheduledThreadPoolExecutor并在提交作业后立即调用shutdown。 因为根据文档关机不杀死提交的任务,运行任务并允许它完成。会工作吗?
问题是关机后,我们可以继续使用ScheduledThreadPoolExecutor提交的未来对象返回。
private static Future submitACall(Callable callableDelegate) { ScheduledThreadPoolExecutor threadPoolExe = null; try { threadPoolExe = new ScheduledThreadPoolExecutor(1); return threadPoolExe.submit(callableDelegate); } finally { threadPoolExe.shutdown(); } } //in another method... if(future.isDone()) future.get();