Manish
Manish

Reputation: 3968

Spring Boot: Configure Job Scheduler Pool via Annotation

I have a Spring Boot Application with a bunch of background jobs. I have added the following Annotation on my main application class:

@SpringBootApplication
@EnableScheduling
public class MyApplication {

In the job class, I have following configuration:

@Component
public class MyTask {
 @Scheduled(fixedDelay = 14400000)
 public void doSomething()

Right now, Spring Boot is executing the jobs in a sequential manner, i.e., one job at a time. This seems most likely due to a single thread based pool. Is there any Annotation/property that can be used to increase the thread pool size? Till now, I have found a solution here, but it requires writing a new Configuration class. Ideally, it should be a property in application.properties file.

Upvotes: 0

Views: 1759

Answers (2)

Adam
Adam

Reputation: 2279

I don't see a property for this in https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html and I don't see any annotation in the docs.

If you want it configurable at that level, just create your own custom properties, which you inject into the other solution you found.

Upvotes: 1

Sigrist
Sigrist

Reputation: 1471

I usually don't put business logic inside a @Scheduled method, instead, I call another method in other component and this method has the @Async annotation. When your scheduled job is fired, then it calls the async method in another thread and you scheduler is free to run other jobs.

Check more how to do it here: https://docs.spring.io/spring/docs/current/spring-framework-reference/html/scheduling.html#scheduling-annotation-support

Upvotes: 1

Related Questions