Created
October 10, 2018 10:51
-
-
Save mwarman/7b221db5a296a9b57e72d03ed38eae08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.leanstacks.scheduling; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.context.properties.EnableConfigurationProperties; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.scheduling.TaskScheduler; | |
import org.springframework.scheduling.annotation.EnableScheduling; | |
import org.springframework.scheduling.annotation.SchedulingConfigurer; | |
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; | |
import org.springframework.scheduling.config.ScheduledTaskRegistrar; | |
@Configuration | |
@EnableConfigurationProperties(SchedulingProperties.class) | |
@EnableScheduling | |
public class SchedulingConfiguration implements SchedulingConfigurer { | |
@Autowired | |
private transient SchedulingProperties schedulingProperties; | |
@Override | |
public void configureTasks(final ScheduledTaskRegistrar taskRegistrar) { | |
taskRegistrar.setScheduler(taskScheduler()); | |
} | |
@Bean | |
public TaskScheduler taskScheduler() { | |
final ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); | |
scheduler.setPoolSize(schedulingProperties.getPool().getSize()); | |
scheduler.setThreadNamePrefix(schedulingProperties.getPool().getThreadNamePrefix()); | |
return scheduler; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment