spring @Scheduled带注释的方法是否在不同的线程上运行? [英] Does spring @Scheduled annotated methods runs on different threads?
问题描述
我有几个用@Scheduled注释的方法(fixedDelay = 10000)。
I have several methods annotated with @Scheduled(fixedDelay=10000).
在应用程序上下文中,我有这个注释驱动的设置:
In the application context, I have this annotation driven setup:
<task:annotation-driven />
问题是,有时一些方法执行会延迟几秒甚至几分钟。
The problem is, sometimes some of the method execution gets delayed by seconds and even minutes.
我假设即使方法需要一段时间才能完成执行,其他方法仍然会执行。所以我不明白延迟。
Im assuming that even if a method takes a while to finish executing, the other methods would still execute. So I don't understand the delay.
有没有办法可以减少甚至消除延迟?
Is there a way to maybe lessen or even remove the delay?
推荐答案
如果您不提供pool-size属性,则默认线程池将只有一个线程。
If you do not provide a pool-size attribute, the default thread pool will only have a single thread.
因此,如果您有许多计划任务,您应该按照文档中的说明配置调度程序,以使具有更多线程的池成为可能确定一项长期任务不会延迟所有其他任务。
So if you have many scheduled tasks, you should configure the scheduler, as explained in the documentation, to have a pool with more threads, to make sure one long task doesn't delay all the other ones.
这篇关于spring @Scheduled带注释的方法是否在不同的线程上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!