Spring Boot (七):整合定时任务schedule

本文介绍了如何在Spring Boot中配置和使用定时任务,包括通过application.properties设置任务时间,创建定时任务类,以及如何实现异步跑批。示例展示了启动类和控制类的代码,探讨了开启异步跑批前后的区别。
摘要由CSDN通过智能技术生成

介绍
定时任务用于定时去执行某项操作,如:跑批数据,报表等。
一、配置文件
采用读取配置文件方式经行时间配置
application.properties

corn=*/1 * * * * *

二、代码
启动类

package com.guo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling 开启定时任务,自动扫描
public class SpringbootScheduleApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringbootScheduleApplication.class, args);
    }
}

定时任务类

package com.guo.task;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class Task {
    @Scheduled(cron = "${corn}")
    public void task(){
    	System.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值