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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-24 我要评论
想了解Spring Boot定时任务的使用实例代码的相关内容吗,在本文为您仔细讲解spring boot 定时任务的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:spring,boot,定时任务,下面大家一起来学习吧。

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定时任务的使用实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们