Spring Boot @Async: 暂停执行

huangapple 未分类评论44阅读模式
英文:

Spring Boot @Async: Pause Execution

问题

在Spring Boot中,是否有一种方法可以在运行时暂停使用@Async注解的方法的执行,直到满足某个条件或经过一段时间?

在Spring Boot微服务中,我有一个REST控制器,同步接收请求,然后调用一个使用@Async注解的委托来运行资源密集型任务。

每天,该微服务都需要读取大型CSV文件并对其进行解析,这大约需要1-2分钟。在此期间,我希望暂停异步方法的执行,但保留队列,以便在所有读取和解析完成后,它将继续运行异步方法。

英文:

In Spring Boot is there a way to pause the execution of @Async Annotated Methods at runtime until a condition is met or for a duration?

In a Spring Boot Microservice I have a REST Controller which accepts request synchronously and then calls a delegate annotated with @Async to run resource heavy jobs.

Every day the Microservice has to read large csv files and parse them, which takes about 1-2 Minutes. For this period I would like to pause the execution of the Async Method but keep the queue, so that as soon as all the reading and parsing is done, it will then continue to run the Async methods.

huangapple
  • 本文由 发表于 2020年4月9日 22:43:43
  • 转载请务必保留本文链接:https://java.coder-hub.com/61123801.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定