From 525b7b913a8e405c07f6671c25a4dda8c0943f89 Mon Sep 17 00:00:00 2001 From: kwoyke Date: Tue, 28 Dec 2021 14:54:23 +0100 Subject: [PATCH] BAEL-5247: Add TaskScheduler config example (#11626) --- .../baeldung/scheduling/SpringSchedulingConfig.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spring-scheduling/src/main/java/com/baeldung/scheduling/SpringSchedulingConfig.java b/spring-scheduling/src/main/java/com/baeldung/scheduling/SpringSchedulingConfig.java index 5d7f1cf88f..4bdfad3267 100644 --- a/spring-scheduling/src/main/java/com/baeldung/scheduling/SpringSchedulingConfig.java +++ b/spring-scheduling/src/main/java/com/baeldung/scheduling/SpringSchedulingConfig.java @@ -5,7 +5,9 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; @Configuration @EnableScheduling @@ -13,6 +15,14 @@ import org.springframework.scheduling.annotation.EnableScheduling; @PropertySource("classpath:springScheduled.properties") public class SpringSchedulingConfig { + @Bean + public TaskScheduler taskScheduler() { + ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); + threadPoolTaskScheduler.setPoolSize(5); + threadPoolTaskScheduler.setThreadNamePrefix("ThreadPoolTaskScheduler"); + return threadPoolTaskScheduler; + } + @Bean public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { return new PropertySourcesPlaceholderConfigurer();