在springboot項(xiàng)目中使用quartz如何實(shí)現(xiàn)一個(gè)定時(shí)任務(wù)-創(chuàng)新互聯(lián)

今天就跟大家聊聊有關(guān)在springboot項(xiàng)目中使用quartz如何實(shí)現(xiàn)一個(gè)定時(shí)任務(wù),可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

10年積累的做網(wǎng)站、成都做網(wǎng)站經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先做網(wǎng)站后付款的網(wǎng)站建設(shè)流程,更有石林免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

spring支持多種定時(shí)任務(wù)的實(shí)現(xiàn)。我們來介紹下使用spring的定時(shí)器和使用quartz定時(shí)器

1.我們使用spring-boot作為基礎(chǔ)框架,其理念為零配置文件,所有的配置都是基于注解和暴露bean的方式。

2.使用spring的定時(shí)器:

spring自帶支持定時(shí)器的任務(wù)實(shí)現(xiàn)。其可通過簡(jiǎn)單配置來使用到簡(jiǎn)單的定時(shí)任務(wù)。

@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分鐘執(zhí)行一次
  @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");
  }
  
}

新聞標(biāo)題:在springboot項(xiàng)目中使用quartz如何實(shí)現(xiàn)一個(gè)定時(shí)任務(wù)-創(chuàng)新互聯(lián)
網(wǎng)站地址:http://bm7419.com/article22/dgdcjc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、做網(wǎng)站、虛擬主機(jī)、用戶體驗(yàn)、標(biāo)簽優(yōu)化、微信公眾號(hào)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)