当前位置: 移动技术网 > IT编程>开发语言>Java > Spring Boot定时任务的使用实例代码

Spring Boot定时任务的使用实例代码

2019年07月22日  | 移动技术网IT编程  | 我要评论

spring boot中配置定时任务极其简单......下面看下实例代码:

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.date;
/**
 * created by winner_0715 on 2017/4/18.
 */
@configuration
@enablescheduling
public class schedulingconfig {
  // 每5秒执行一次
  @scheduled(cron = "0/5 * * * * ?")
  public void scheduler() {
    system.out.println("schedulingconfig.scheduler()" + 
        new simpledateformat("yyyy-mm-dd hh:mm:ss").format(new date()));
  }
}

以上所述是小编给大家介绍的spring boot定时任务的使用实例代码,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网