SpringBoot中定时任务、corn表达式

SpringBoot中定时任务、corn表达式

corn表达式网站:https://cron.qqe2.com/

方法上加上@Scheduled(cron=表达式)

启动类上加上@EnableScheduling

示例

启动类上

启动类加上@EnableScheduling开启定时任务。

@SpringBootApplication
@EnableScheduling
public class DemoTaskApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoTaskApplication.class, args);
    }
}

在这里插入图片描述

方法上

实现每秒执行一次

corn表达式网站:https://cron.qqe2.com/

@Scheduled(cron = "0/1 * * * * ?")
public void test() {
    System.out.println("cron表达式----");
}

每隔一秒输出一次。
在这里插入图片描述

相关推荐

  1. SpringBoot 定时任务之@Scheduled cron表达式

    2024-03-12 04:08:02       21 阅读
  2. 3分钟搞定springboot 定时任务cron表达式

    2024-03-12 04:08:02       60 阅读
  3. springboot定义cron定时任务执行

    2024-03-12 04:08:02       60 阅读
  4. CRON 定时任务

    2024-03-12 04:08:02       38 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-12 04:08:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-12 04:08:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-12 04:08:02       87 阅读
  4. Python语言-面向对象

    2024-03-12 04:08:02       96 阅读

热门阅读

  1. LCR 172. 统计目标成绩的出现次数(二分查找)

    2024-03-12 04:08:02       33 阅读
  2. 蓝桥杯2023年-更小的数(字符串,推理)

    2024-03-12 04:08:02       41 阅读
  3. Android Selinux详解[二]--新增文件标签相关

    2024-03-12 04:08:02       44 阅读
  4. qwen API调用

    2024-03-12 04:08:02       57 阅读
  5. 【MyBatis-Plus 常用注解详解】

    2024-03-12 04:08:02       39 阅读