javascript
SpringBoot中的Quartz应用
?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:28Quartz:
使用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)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 第0次个人作业
- 下一篇: JS魔法堂:doctype我们应该了解的