springboot计划任务实现方法

springboot计划任务实现方法

http://cron.qqe2.com/

在线cron表达式生成

@EnableScheduling
public class PlanTaskApplication {

加声明EnableScheduling


package com.example.plan_task;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Service
public class TaskService {
@Scheduled(fixedRate = 5000)
public void task1(){
System.out.println("task1每5秒 一次");
}

@Scheduled(cron = "2/5 * * * * ? ")
public void task2(){
System.out.println("task2指定时间");
}


}

原文地址:https://www.cnblogs.com/zhanying999666/p/7421489.html