@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

相关推荐
OH_TPC2 小时前
HarmonyOS APP开发---“滤镜大师“图像处理App,需要用到这个库
java·图像处理·华为·harmonyos·鸿蒙
imaol13 小时前
链表 -- 环链表
java·前端·链表
imaol13 小时前
链表 -- 双向链表
java·前端·链表
2601_963869954 小时前
【计算机毕业设计】基于Java的相框定制系统的设计与实现
java·开发语言·课程设计
于烛5 小时前
为什么hasNext() 对只有一个元素的集合返回 true?90%初学者都有的疑问
java
wuminyu5 小时前
JVM利用io_uring优化堆外内存性能原理剖析
java·linux·c语言·jvm·c++
imaol15 小时前
数据结构---队列
java·数据结构·算法
半亩码田6 小时前
【.NET新特性·第11篇】C# 14 字段属性:告别手写 backing field
java·c#·.net
JAVA面经实录9176 小时前
集合框架 (六)
java·开发语言
骇客野人6 小时前
Linux 查看 Java 进程常用命令
java·linux·运维