pringboot实现定时任务Schedule

参考文档:https://www.cnblogs.com/0201zcr/p/5995779.html

 

代码实列:

package com.examples.springboots.task;

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

/**
 * @author: CSH
 * @description: 线程列表
 * @create: 2020-04-22 09:51
 **/
@Component
public class BaseTask {
    /**
     * 秒 分  时  天  月  年
     */
    @Scheduled(cron = "0/5 * * * * *")
    public void scheduled() {
        System.out.println("=====>>>>>使用cron  {}" + System.currentTimeMillis());
    }

    @Scheduled(fixedRate = 5000)
    public void scheduled1() {
        System.out.println("=====>>>>>使用fixedRate{}" + System.currentTimeMillis());
    }

    @Scheduled(fixedDelay = 5000)
    public void scheduled2() {
        System.out.println("=====>>>>>fixedDelay{}" + System.currentTimeMillis());
    }
}

 

posted @ 2020-04-22 10:29  土木转行的Genius  阅读(151)  评论(0)    收藏  举报