【发布时间】:2012-11-28 22:05:44
【问题描述】:
我有这个使用:Spring MVC (Controller + Service + ThreadPoolTaskExecutor)、Callable 和 Future。
@Controller
launch-method [invokes Service:launch-method and get result with Future]
stop-method [invokes Service:stop-method]
@Service [to launch async Tasks]
launch-method [Loop with threadPoolTaskExecutor.submit(callable)]
stop-method [threadPoolTaskExecutor.shutdown()]
我拥有的停止事件流是:
- 用户单击停止按钮并调用 控制器:停止方法
- Controller: stop-method 调用 Service: stop-method
- ¿ Service: stop-method 关闭并通知 Controller: launch-method
我需要编写步骤 3 的代码,以通知 Controller:launch-method 该过程已完成。
我不知道为什么 threadPoolTaskExecutor.shutdown() 没有释放 Controller:launch-method,它正在等待:result = future.get(); em> 并且没有引发异常。
try {
for (Future<String> future : sentResult) {
result = future.get();
...
}
} catch (ExecutionException e) {...}
catch (InterruptedException e) {...}
catch (CancellationException e) {...}
catch (Exception e) {...}
有什么建议吗?
【问题讨论】:
标签: java multithreading spring-mvc future callable