Skip to content

Instantly share code, notes, and snippets.

@mwarman
Created October 10, 2018 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwarman/7b221db5a296a9b57e72d03ed38eae08 to your computer and use it in GitHub Desktop.
Save mwarman/7b221db5a296a9b57e72d03ed38eae08 to your computer and use it in GitHub Desktop.
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