All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.allbs.scheduled.TaskSchedulingConfig Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package cn.allbs.scheduled;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

/**
 * @author ChenQi
 */
@Configuration
@EnableAsync
@EnableScheduling
public class TaskSchedulingConfig {

    @Bean
    public TaskScheduler taskScheduler() {
        ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
        // 定时任务执行线程池核心线程数
        taskScheduler.setPoolSize(10);
        taskScheduler.setRemoveOnCancelPolicy(true);
        taskScheduler.setThreadNamePrefix("DynamicAllbsSchedulerThreadPool-");
        return taskScheduler;
    }

    @Bean
    @ConditionalOnMissingBean(CronTaskRegistrar.class)
    public CronTaskRegistrar cronTaskRegistrar() {
        return new CronTaskRegistrar(taskScheduler());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy