任务调度
1、在启动类添加注解@EnableScheduling,开启Spring Boot 任务定时任务功能。
- @SpringBootApplication
- @EnableScheduling
- @EnableAutoConfiguration
- public class QuartApplication {
-
-
- public static void main(String[] args) {
- try {
- //BaiDuAIUtil.sample();
- SpringApplication.run(QuartApplication.class, args);
- } catch (Exception e) {
- System.out.println(e);
- }
-
- }
-
-
- }
2、配置线程池
- @Configuration
- @EnableAsync
- @ConfigurationProperties(prefix = "springquartz.task")
- public class TaskConfig {
-
- //线程池最小数量
- private int corePoolSize;
- //线程池最大数量
- private int maxPoolSize;
- // 缓冲队列长度
- private int queueCapacity;
-
- public int getCorePoolSize() {
- return corePoolSize;
- }
-
- public void setCorePoolSize(int corePoolSize) {
- this.corePoolSize = corePoolSize;
- }
-
- public int getMaxPoolSize() {
- return maxPoolSi