springboot的schedule任务配置

任务类配置:

package com.abc.schedule;

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

import java.text.SimpleDateFormat;
import java.util.Date;

/*
         *  author  :  ajing
         *  date    :  2018/4/10 10:22
         * */
@Service   //注意要在启动类里加@EnableScheduling注解
public class ScheduleTaskService {
    private static  final SimpleDateFormat dateFormat=new SimpleDateFormat("HH:mm:ss");

    @Scheduled(fixedRate = 500)  //fixedDelay表示以任务结束为标志5秒执行一个任务,fixedRate表示以任务开始为标志5秒执行一个任务
    public  void reportCurrentTime(){
        System.out.println("每隔500毫秒执行一次"+dateFormat.format(new Date()));
    }
    @Scheduled(cron = "0 30 10 ? * *") //秒分钟小时天月星期,*/*第一个*表示起始量 第二个*表示增量
    public  void fixTimeExecute(){
        System.out.println("在指定时间执行:"+dateFormat.format(new Date()));
    }
}

结果:


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值