日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

SpringBoot中的Quartz应用

發(fā)布時間:2025/3/19 javascript 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringBoot中的Quartz应用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?Spring自帶定時器任務(wù):

code:

import org.springframework.beans.factory.annotation.Configurable; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component;import java.text.SimpleDateFormat; import java.util.Date;@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/4 * * * * * ")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");} }

Output:

Scheduling Tasks Examples By Cron: The time is now 12:02:48 Scheduling Tasks Examples By Cron: The time is now 12:02:52 Scheduling Tasks Examples: The time is now 12:02:54 Scheduling Tasks Examples By Cron: The time is now 12:02:56 Scheduling Tasks Examples By Cron: The time is now 12:03:00 Scheduling Tasks Examples By Cron: The time is now 12:03:04 Scheduling Tasks Examples By Cron: The time is now 12:03:08 Scheduling Tasks Examples By Cron: The time is now 12:03:12 Scheduling Tasks Examples By Cron: The time is now 12:03:16 Scheduling Tasks Examples By Cron: The time is now 12:03:20 Scheduling Tasks Examples By Cron: The time is now 12:03:24 Scheduling Tasks Examples: The time is now 12:03:24 Scheduling Tasks Examples By Cron: The time is now 12:03:28

Quartz:

使用quartz實現(xiàn)定時任務(wù)。
  Quartz設(shè)計者做了一個設(shè)計選擇來從調(diào)度分離開作業(yè)。Quartz中的觸發(fā)器用來告訴調(diào)度程序作業(yè)什么時候觸發(fā)。框架提供了一把觸發(fā)器類型,但兩個最常用的是SimpleTrigger和CronTrigger。

? ? ? ?SimpleTrigger為需要簡單打火調(diào)度而設(shè)計。典型地,如果你需要在給定的時間和重復次數(shù)或者兩次打火之間等待的秒數(shù)打火一個作業(yè),那么SimpleTrigger適合你。另一方面,如果你有許多復雜的作業(yè)調(diào)度,那么或許需要CronTrigger。
? ? ? ?CronTrigger是基于Calendar-like調(diào)度的。當你需要在除星期六和星期天外的每天上午10點半執(zhí)行作業(yè)時,那么應(yīng)該使用CronTrigger。正如它的名字所暗示的那樣,CronTrigger是基于Unix克隆表達式的。

?

http://blog.csdn.net/github_34889651/article/details/52586234

https://my.oschina.net/hhaijun/blog/698498

http://www.jianshu.com/p/67c760de79d5

http://blog.csdn.net/loongshawn/article/details/52078134

http://www.cnblogs.com/lic309/p/4089633.html

總結(jié)

以上是生活随笔為你收集整理的SpringBoot中的Quartz应用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。