@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

相关推荐
咩咩啃树皮6 小时前
第40篇:Vue3组件化开发精讲——组件拆分、复用、父子通信、工程化架构
java·前端·架构
鱟鲥鳚7 小时前
Spring Boot 集成 LangChain4j:从模型调用到 Tool Calling(Demo版)
java·spring boot
大模型码小白8 小时前
【Python零基础教程】继承、多态与魔法函数:面向对象编程三大核心特性详解
java·大数据·开发语言·人工智能·python·ai编程
腾渊信息科技公司9 小时前
Spring Boot对接MES实战:视觉检测数据自动同步方案
java·人工智能·spring boot·后端·计算机视觉·ai·软件需求
爱笑的源码基地10 小时前
高并发 Redis 缓存门诊HIS系统源码,含财务统计药房进销存
java·程序·门诊系统·诊所系统·云诊所源码
wuqingshun31415910 小时前
TCP超时重传机制是为了解决什么问题?
java
莫逸风12 小时前
【AgentScope 2.0】 0. 学习指南
java·llm·agent·agentscope
z1234567898613 小时前
2026最新两款AI编程工具深度对比实测
java·数据库·ai编程
yaoxin52112313 小时前
470. Java 反射 - Member 接口与 AccessFlag
java·开发语言·python
做个文艺程序员14 小时前
Linux第24篇:Java应用监控体系搭建:Prometheus+Grafana可视化运维
java·grafana·prometheus