Reputation: 1044
I have a Spring boot 2.1.6.RELEASE application in which I have a method annotated with
@Scheduled(cron = "*/10 * * * * *}
I want it to run with that cron, EVEN IF another execution is already in progress.
I tried increasing the executor thread number using the application.properties file:
spring.task.scheduling.pool.size=10
But it didn't seem to work as it is still waiting for an execution to finish before starting the next one.
What is the proper way to do parallel executions using a cron in the @Scheduled annotation?
Upvotes: 3
Views: 1701
Reputation: 468
It is true that the default pool size for the task scheduler is 1 but increasing this pool size is only making more threads available for other @Scheduled
methods. The intended behaviour is not for methods to run in parallel as otherwise threads could become exhausted.
If you wish to change this behaviour to allow the same method to run in parallel you need to use @EnableAsync
and @Async
annotations. You might also want to change the pool size of the task executor. That being said, keep in mind that you may still exhaust your threads so be very careful with changing this intended behaviour.
Upvotes: 4