springboot中配置定时任务(cron表达式)线程池方式

项目地址:https://github.com/heng1234/springboot2.x/tree/master/boot_task

Quartz Cron表达式在线生成地址:http://cron.qqe2.com/

开始使用:

首先在启动类加上@EnableScheduling开启定时任务

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

//开启定时任务
@EnableScheduling
@SpringBootApplication
public class BootTaskApplication {

    public static void main(String[] args) {
        SpringApplication.run(BootTaskApplication.class, args);
    }

}

接着配置线程池

使用定时任务:

运行项目控制台打印:

image-20191111095924048

下一章:springboot发送邮箱

Last updated

Was this helpful?