Spring @Async线程永不完成会发生什么?

问题描述

如果您有@Async方法,则返回CompletableFuture...。并且将来的永不完成,spring是否会泄漏线程?是的,我知道等待结果的任何人都可能会超时,并且在以后阶段假定会异常完成。.....但这不会停止线程。即使您调用cancel,它也不会对正在运行的线程起作用:

来自文档:

@param mayInterruptIfRunning此值对此无效 实现,因为不使用中断来控制 处理。

如果我使用Future而不是CompletableFuture,则cancel将中断线程。不幸的是,在Future上没有等效的“ allOf”,就像我们在CompletableFuture上等待所有任务一样,

// wait for all the futures to finish,regardless of results
CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new))
   // if exceptions happened in any future,swallow them
   // I don't care because I'm going to process each future in my list anyway
   // we just wanted to wait for all the futures to finish
   .exceptionally(ex -> null); 
  1. 我们应该如何取消受保的线程?
  2. 如果我不取消(以某种方式取消),我的泳池会永远处于线程关闭状态吗???

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)