首页 > 编程语言 > 详细

170627、springboot编程之定时任务

时间:2017-08-21 21:29:40      阅读:303      评论:0      收藏:0      [点我收藏+]

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、项目清单

技术分享

 

170627、springboot编程之定时任务

原文:http://www.cnblogs.com/zrbfree/p/7406670.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!