Does spring @Scheduled annotated methods runs on different threads?

Spring 4.x

Code below shows the simplest possible way to configure scheduler with java config:

@Configuration
@EnableScheduling
public class SpringConfiguration {

    @Bean(destroyMethod = "shutdown")
    public Executor taskScheduler() {
        return Executors.newScheduledThreadPool(5);
    }
    ...

When more control is desired, a @Configuration class may implement SchedulingConfigurer.

Spring Boot

In Spring Boot there is a simple property to configure the thread pool size:

spring.task.scheduling.pool.size=5

Leave a Comment

tech