@Scheduled(cron = “1 0 0 * * ?“用法介绍

@Scheduled 语法学习记录

  • [@Scheduled(cron = "1 0 0 * * ?")](#@Scheduled(cron = "1 0 0 * * ?"))

@Scheduled(cron = "1 0 0 * * ?")

1 .@Scheduled 方法的使用 说明

javascript 复制代码
    //0 0 * * * ?     每小时执行一次
    //0 0 */1 * * ?   每小时执行一次
    //* * 0/1 * * ?   每小时执行一次

    //0 0/2 * * * ?   每两分钟

    //0/1 * * * * ?  每一秒执行一次
    //0 0 0/1 * * ?   每小时执行一次
    //0/20 * * * * ?  每20秒执行一次


   // @Scheduled(cron = "0 0 0 * * ?") // 每天零点执行一次


    @Scheduled(cron = "1 0 0 * * ?") // 每天零点零一分执行一次
    public void performTask() {
        System.out.println("Task executed at 00:01");
        // 你的业务逻辑代码写在这里
    }
    
复制代码
Cron表达式解释:
0 秒
1 分(即第1分钟)
0 小时(即零点)
* 日(每一天)
* 月(每一个月)
? 星期中的天(不指定,因为我们已经指定了日)
  1. 启用定时任务
    在你的主类或者配置类上添加@EnableScheduling注解来启用定时任务支持:
javascript 复制代码
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableScheduling
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
  1. 添加依赖

    org.springframework.boot spring-boot-starter-parent 2.x.x.RELEASE org.springframework.boot spring-boot-starter

// 参考 百度Ai https://www.baidu.com

相关推荐
天河归来3 小时前
第三方接口不稳定,如何让核心任务继续完成
java·大数据
Knight_AL3 小时前
Java 文件下载时文件名中的 `#` 被转换成 `%23`?一次 URL 编码与解码问题排查
java·开发语言
砚底藏山河4 小时前
python量化自定义周期 K 线合成
java·开发语言·数据库·python·金融
猿究院_夏燊5 小时前
MySQL 的四种隔离级别
java·数据库·mysql
码流子6 小时前
移动收费怎么做?手持终端+App+收费中心的架构实践
java·开发语言·架构
霸道流氓气质6 小时前
AI 流式对话与实时聊天平台:SSE 解码竞态、有状态会话隔离与背压取消的 Vue3 + Spring AI 生产级实战
java·人工智能·spring
云创智城-yuncitys6 小时前
YunParking 4.0:JDK 17 与 Spring Boot 3.2 的停车云升级
java·开发语言·spring boot
文丑颜不良啊6 小时前
LeetCode1661~1680题目解析
java·leetcode
子非鱼@Itfuture6 小时前
关于前后端联调中登录状态/登录信息失效?
java·前端
郭小李6 小时前
openFeign入门
java·开发语言·前端