170627、springboot编程之定时任务

springboot定时任务,比较简单!

1、编写DemoSchedule.java类

package com.rick.common.schedule;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * Desc :  定时任务
 * User : RICK
 * Time : 2017/8/21 21:16
  */
@Configuration
@EnableScheduling
public class DemoSchedule {

    //cron表达式 秒分时 日月周 年
    @Scheduled(cron = "0/10 * * * * ?") //每10秒执行一次
    public void demoPrint(){
        System.out.println("现在时间:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()));
    }
}

2、启动项目测试

3、项目清单

原文地址:https://www.cnblogs.com/zrbfree/p/7406670.html