新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

在springboot项目中使用quartz如何实现一个定时任务-创新互联

今天就跟大家聊聊有关在springboot项目中使用quartz如何实现一个定时任务,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

10年积累的做网站、成都做网站经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先做网站后付款的网站建设流程,更有石林免费网站建设让你可以放心的选择与我们合作。

spring支持多种定时任务的实现。我们来介绍下使用spring的定时器和使用quartz定时器

1.我们使用spring-boot作为基础框架,其理念为零配置文件,所有的配置都是基于注解和暴露bean的方式。

2.使用spring的定时器:

spring自带支持定时器的任务实现。其可通过简单配置来使用到简单的定时任务。

@Component
@Configurable
@EnableScheduling
public class ScheduledTasks{

  @Scheduled(fixedRate = 1000 * 30)
  public void reportCurrentTime(){
    System.out.println ("Scheduling Tasks Examples: The time is now " + dateFormat ().format (new Date ()));
  }

  //每1分钟执行一次
  @Scheduled(cron = "0 */1 * * * * ")
  public void reportCurrentByCron(){
    System.out.println ("Scheduling Tasks Examples By Cron: The time is now " + dateFormat ().format (new Date ()));
  }

  private SimpleDateFormat dateFormat(){
    return new SimpleDateFormat ("HH:mm:ss");
  }
  
}

网页标题:在springboot项目中使用quartz如何实现一个定时任务-创新互联
转载来于:http://www.wjwzjz.com/article/dgdcjc.html
在线咨询
服务热线
服务热线:028-86922220
TOP