Quartz2.2.0 产生misfire条件参数misfireThreshold和misfire策略详细说明

2023-10-27


首先,misfire产生的条件是:misfire的时间间隔大于配置里设置的misfireThreshold值,就认为是misfire了,错失触发了。


比如:13:07:24开始执行,重复执行5次,开始执行时,quartz已经计算好每次调度的时间刻,分别如下:

03:33:36,03:33:39,03:33:42,03:33:45,03:33:48,03:33:51

如果第一次执行时间为11s,到03:33:47结束,03:33:47减去03:33:39的时间间隔是8s,如果misfireThreshold设置的时间小于等于8s,则认为是misfire了,如果大于8s,则认为没有misfire。


假如Misfire策略是MISFIRE_INSTRUCTION_FIRE_NOW,对错失的调度不处理,


如果misfireThreshold = 9,即<prop key="org.quartz.jobStore.misfireThreshold">9000</prop>  ,处理输出如下:(并 没有misfire)

QuartzMissfireJob的任务调度[1585915091]开始:2014-02-17 03:33:36
QuartzMissfireJob的任务调度[1585915091]结束2014-02-17 03:33:47
QuartzMissfireJob的任务调度[1031004174]开始:2014-02-17 03:33:47
QuartzMissfireJob的任务调度[1031004174]结束2014-02-17 03:33:49
QuartzMissfireJob的任务调度[1762116878]开始:2014-02-17 03:33:49
QuartzMissfireJob的任务调度[1762116878]结束2014-02-17 03:33:51
QuartzMissfireJob的任务调度[297927453]开始:2014-02-17 03:33:51
QuartzMissfireJob的任务调度[297927453]结束2014-02-17 03:33:53
QuartzMissfireJob的任务调度[1141610173]开始:2014-02-17 03:33:53
QuartzMissfireJob的任务调度[1141610173]结束2014-02-17 03:33:55
QuartzMissfireJob的任务调度[1222040615]开始:2014-02-17 03:33:55
QuartzMissfireJob的任务调度[1222040615]结束2014-02-17 03:33:57

如果misfireThreshold = 8,即<prop key="org.quartz.jobStore.misfireThreshold">8000</prop>  ,处理输出如下:(misfire了)

QuartzMissfireJob的任务调度[905379918]开始:2014-02-17 03:53:33
QuartzMissfireJob的任务调度[905379918]结束2014-02-17 03:53:44
QuartzMissfireJob的任务调度[573294390]开始:2014-02-17 03:53:44
QuartzMissfireJob的任务调度[573294390]结束2014-02-17 03:53:46
QuartzMissfireJob的任务调度[1944119278]开始:2014-02-17 03:53:47
QuartzMissfireJob的任务调度[1944119278]结束2014-02-17 03:53:49
QuartzMissfireJob的任务调度[505858271]开始:2014-02-17 03:53:50
QuartzMissfireJob的任务调度[505858271]结束2014-02-17 03:53:52


在quartz里,org.quartz.jobStore.misfireThreshold: 60000,默认是60s

在spring配置文件中,如果没有配置<prop key="org.quartz.jobStore.misfireThreshold">8000</prop>  属性,那么misfireThreshold会为0



当产生misfire时,会有多种处理策略,Quartz2.2.0 + Spring4.0.0版本配置文件中misfire策略详细说明:

关键是

<property name="misfireInstruction"><value>0</value></property>
这个属性


SimpleTrigger说明:


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="http://www.springframework.org/schema/beans	http://www.springframework.org/schema/beans/spring-beans.xsd">

	<!-- 启动触发器的配置开始 -->
	<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序  -->
	<bean name="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="triggers">
			<!-- 调度清单 -->
			<list>
				<ref bean="simpleTrigger" />
			</list>
		</property>
		<!-- quartz配置 -->  
		<property name="quartzProperties">  
			<props>  
				<prop key="org.quartz.threadPool.threadCount">10</prop>  
				<prop key="org.quartz.jobStore.misfireThreshold">1</prop>  
			</props>  
		</property>  
		<!-- 初始化之后延迟3秒启动scheduler -->  
		<!-- 
		<property name="startupDelay">  
			<value>1</value>  
		</property>  
		-->
	</bean>
	
	<!-- 启动触发器的配置结束 -->

	<!-- 调度的配置开始 -->
	<!--
			quartz-1.8以前的配置 
		<bean id="myJobTrigger"
			class="org.springframework.scheduling.quartz.CronTriggerBean">
			<property name="jobDetail">
				<ref bean="myJobDetail" />
			</property>
			<property name="cronExpression">
				<value>0/1 * * * * ?</value>
			</property>
		</bean>
		-->
	<!-- quartz-2.x的配置 -->
	<!-- 定义触发时间 -->
	<!-- cronTrigger简单触发器配置 -->
	<!-- 默认是withMisfireHandlingInstructionFireAndProceed —— 以当前时间为触发频率立刻触发一次执行,然后按照Cron频率依次执行,如没有空闲进程可用,则kill掉前面那个调度,立即触发当前这个-->
	<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
		<property name="jobDetail">
			<ref bean="simpleJobDetail"/>
		</property>
		<!-- <property name="startDelay" value="1" /> -->
		<!-- 每3s执行一次 -->
		<property name="repeatInterval" value="3000" />
		<property name="repeatCount" value="5" />
		<!-- 
			MISFIRE_INSTRUCTION_FIRE_NOW    1  
			
			Instructs the Scheduler that upon a mis-fire situation, the SimpleTrigger wants to be fired now by Scheduler. 
			
			NOTE: This instruction should typically only be used for 'one-shot' (non-repeating) Triggers. If it is used on a trigger with a repeat count > 0 then it is equivalent to the instruction MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT . 
			立即执行,会丢失misfire job,等效于MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT
			
			
			MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT   3
			
			Instructs the Scheduler that upon a mis-fire situation, the SimpleTrigger wants to be re-scheduled to 'now' (even if the associated Calendar excludes 'now') with the repeat count set to what it would be, if it had not missed any firings. This does obey the Trigger end-time however, so if 'now' is after the end-time the Trigger will not fire again. 
			
			NOTE: Use of this instruction causes the trigger to 'forget' the start-time and repeat-count that it was originally setup with. Instead, the repeat count on the trigger will be changed to whatever the remaining repeat count is (this is only an issue if you for some reason wanted to be able to tell what the original values were at some later time). 
			
			NOTE: This instruction could cause the Trigger to go to the 'COMPLETE' state after firing 'now', if all the repeat-fire-times where missed. 
			立即执行,继续重复执行的次数等于本次+剩余的次数,即剩余次数+1,misfire job不会再执行.
			比如,3s执行一次,重复执行5次,05:08:11开始执行,那么理应重复执行的时间点是05:08:11,05:08:14,05:08:17,05:08:20,05:08:23,05:08:26,
			但如果第一次执行的时间是11s,执行完的时间点是:05:08:22,,那么立即执行的时间点是05:08:22,
			而且从这点开始,还有05:08:23,05:08:26,这两次没执行,所以立即执行后,还会再执行2次。
			所以之后的执行时间点是:05:08:22,05:08:25,05:08:28

			MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT   5
			
			Instructs the Scheduler that upon a mis-fire situation, the SimpleTrigger wants to be re-scheduled to the next scheduled time after 'now' - taking into account any associated Calendar, and with the repeat count left unchanged. 
			
			NOTE/WARNING: This instruction could cause the Trigger to go directly to the 'COMPLETE' state if the end-time of the trigger has arrived. 
			不会立即执行,misfire job不会再执行,到下一个触发点再执行,继续重复执行的次数等于剩余次数-1.
			比如,3s执行一次,重复执行5次,02:28:38开始执行,那么理应重复执行的时间点是02:28:38,02:28:41,02:28:44,02:28:47,02:28:50,02:28:53
			但如果第一次执行时间用了11s,到02:28:49结束,那下次执行时间是02:28:50,02:28:53,只有(2-1)=1次,所以一次执行时间点是:02:28:50

			
			
			MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT  4
			
			Instructs the Scheduler that upon a mis-fire situation, the SimpleTrigger wants to be re-scheduled to the next scheduled time after 'now' - taking into account any associated Calendar, and with the repeat count set to what it would be, if it had not missed any firings. 
			
			NOTE/WARNING: This instruction could cause the Trigger to go directly to the 'COMPLETE' state if all fire-times where missed. 
			不会立即执行,misfire job不会再执行,到下一个触发点再执行,继续重复执行的次数等于剩余次数-1.
			会根据第一次执行的时间,然后从当前时间开始,到终止时间,计算还能执行的剩余次数,重复执行这个剩余次数。相当于重新计算剩余次数,进行调度。
			如:3s执行一次,重复执行5次,从 05:18:52开始,理论上依次执行的时间点是 05:18:55,05:18:58,05:19:01,05:19:04,05:19:07
			但如果第一次执行了11s,到05:19:03结束,则继续按照本来的调度,下次执行的开始时间是05:19:04,接着执行05:19:07
			且错过的05:18:55,05:18:58,05:19:01的触发不会再执行下去


			MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT  2
			
			Instructs the Scheduler that upon a mis-fire situation, the SimpleTrigger wants to be re-scheduled to 'now' (even if the associated Calendar excludes 'now') with the repeat count left as-is. This does obey the Trigger end-time however, so if 'now' is after the end-time the Trigger will not fire again. 
			
			NOTE: Use of this instruction causes the trigger to 'forget' the start-time and repeat-count that it was originally setup with (this is only an issue if you for some reason wanted to be able to tell what the original values were at some later time). 
			立即执行,不会丢失misfire job,从当前时刻开始重新计算每次执行时间点,重做misfire的job
			如:3s执行一次,重复执行5次,05:24:44开始,每次时间点理应是:05:24:47,05:24:50,05:24:53,05:24:56,05:24:59
			但由于第一次执行用了11s,到05:24:55结束,那么从05:24:55开始重新计算剩余次数5次的每次执行的时间点,假设剩余执行每次只需执行2s时间,不会Misfire
			那么剩余执行调度的时间点是:05:24:55,05:24:58,05:25:01,05:25:04,05:25:07
			
			
			
			MISFIRE_INSTRUCTION_SMART_POLICY    0   default 
			
			Instructs the Scheduler that upon a mis-fire situation, the updateAfterMisfire() method will be called on the Trigger to determine the mis-fire instruction, which logic will be trigger-implementation-dependent. 
			
			In order to see if this instruction fits your needs, you should look at the documentation for the getSmartMisfirePolicy() method on the particular Trigger implementation you are using.
			
			如果没有自定义的话,当misfire后,立即执行,不会丢失misfire job... 跟MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT差不多策略
		-->
		<property name="misfireInstruction"><value>0</value></property>
	</bean>
	<!-- 调度的配置结束 -->

	<!-- job的配置开始 -->
	<!-- 定义调用对象和调用对象的方法 -->
	<bean id="simpleJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
		<property name="targetObject" ref="missfireJob" />
		<property name="targetMethod" value="work" />
		<!-- <property name="concurrent" value="false" /> -->
		<!-- 同步执行 -->
		<property name="concurrent" value="false" />
	</bean>
	<!-- job的配置结束 -->

	<!-- 要调用的工作类 -->
	<bean id="missfireJob" class="com.liangbinny.quartz.example6.QuartzMissfireJob" />
</beans>




本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Quartz2.2.0 产生misfire条件参数misfireThreshold和misfire策略详细说明 的相关文章

  • 最常见的两类充电问题解析-电流小和类型识别错误

    前言 充电问题在手机研发和其它的移动设备中是非常常见的一种类型 其中最主要的有两种 充电电流小和类型识别错误 那么在遇到这种充电问题时 我们究竟应该如何分析 才能一步步探究到问题的根源呢 本文即总结了一些常见的充电问题分析手段 以及该分析措

随机推荐

  • js赋值后 改变现有数据会修改原来的数据的解决办法

    来 先看问题 let obj1 name 张三 age 18 sex 男 let obj2 obj1 console log obj2 obj2 obj2 age 22 console log obj2 obj2 console log o
  • ad16中pcb的黑色区域怎么调大

    ad16调大pcb黑色区域不是用的keepoutlay来调整 那都是些水经验的 正确方法 在pcb点击下 按数字键1再按D 可以看见有移动板子顶点选项并点击 快捷键V 然后可以自己拖动定点 设置好大小后 按2退出 黑色区域就变化了
  • Mybatis日期检索格式报错

    问题复现 org mybatis spring MyBatisSystemException nested exception is org apache ibatis exceptions PersistenceException Err
  • 新唐NUC980使用记录(5.10.y内核):访问以太网(LAN8720A) & 启用SSH

    文章目录 目的 修改内核和设备树以访问以太网 制作根文件系统并启用SSH 总结 目的 这篇文章主要测试新唐NUC980 5 10 y内核 访问以太网 PHY为LAN8720A 以及启用SSH 这篇文章中内容均在下面的开发板上进行测试 新唐N
  • CTF-Crypto题目分析__3

    CTF Crypto题目分析 3 题目描述 下载后 发现有个python文件 解题思路 打开ezrsa py 发现 1 需要通过对密文c进行解密得到明文flag c m e mod n 2 q 5 p i q是p的五倍多一点 3 n pqr
  • JSP 9大内置对象 详解

    JSP内置对象 9个常用的内置对象 1 request对象 客户端的请求信息被封装在request对象中 通过它才能了解到客户的需求 然后做出响应 它是HttpServletRequest类的实例 序号方法说明 objectgetAttri
  • 数学建模——人口增长模型的matlab实现以及对2010年人口预测

    文章目录 运行软件 MATLAB R2012a 实验数据 指数增长模型 指数增长模型 方法一 对2010年的人口预测 指数增长模型 方法二 对2010年人口预测 改进的指数增长模型 对2010人口预测 逻辑斯蒂 logistic 模型 逻辑
  • Docker Desktop使用入门

    文章目录 Docker Desktop for Mac Docker Dashboard Docker 仪表板 Containers Apps 容器 容器操作 Docker Compose images 镜像 镜像操作 preference
  • 运筹第三章决策

    第三章决策 一 决策的概念 针对具有明确目标的决策问题 经过调查研究 根据实际与可能 拟定多个可行方案 让后运用统一的表针 选定对甲方按的全过程 二 决策的分类 1 安决策方法不同分类 常规性决策的特殊型决策 2 按照计划和控制的关系分类
  • vsftpd服务器搭建与管理

    安装vsftpd rpm包 mount dev cdrom mnt cd mnt Server cp vsftpd 2 0 5 16 el5 i386 rpm usr usr rpm ivh vsftpd 2 0 5 16 el5 i386
  • 【HTML】解决恶意script脚本输入问题

    项目场景 提示 这里简述项目相关背景 HTML script 安全验证 程序永远不可以相信用户的输入 问题描述 系统做安全测试 发现系统中允许直接调用用户输入的脚本内容 如 系统加载完 会重复执行这个脚本 原因分析 提示 这里填写问题的分析
  • 2021-09-30 学习记录:渐变线的制作

    如上所示渐变线 写法如下 part 4 width 320 remh height 2 remh background image linear gradient 136deg rgba 39 101 150 0 0 rgba 39 221
  • log4j.properties配置详解

    stone 的 log4j配置详解 Log4J的配置文件 Configuration File 就是用来设置记录器的级别 存放器和布局的 它可接key value格式的设置或xml格式的设置信息 通过配置 可以创建出Log4J的运行环境 1
  • 操作系统类型

    unix freebsd VxWorks Solaris Windows xp 7 8 10 Linux Redhat Ubuntu SUSE CentOS mobile Android ios symbian embeded system
  • 前端插件之 Select2 介绍及使用

    Select2是一款基于JQuery的下拉列表插件 主要用来优化select 支持单选和多选 同时也支持分组显示 列表检索 远程获取数据等众多好用的功能 项目地址 select2 org 基本使用 需要用到的JS和CSS文件位于项目代码下的
  • 彻底理解线程

    优质资源分享 学习路线指引 点击解锁 知识定位 人群定位 Python实战微信订餐小程序 进阶级 本课程是python flask 微信小程序的完美结合 从项目搭建到腾讯云部署上线 打造一个全栈订餐系统 Python量化交易实战 入门级 手
  • h2database BTree 设计实现与查询优化思考

    h2database 是使用Java 编写的开源数据库 兼容ANSI SQL89 既实现了常规基于 BTree 的存储引擎 又支持日志结构存储引擎 功能非常丰富 死锁检测机制 事务特性 MVCC 运维工具等 数据库学习非常好的案例 本文理论
  • Python爬虫(七)学习提取网页中所有链接

    import re import urllib request def getlink url headers User Agent Mozilla 5 0 Windows NT 10 0 WOW64 AppleWebKit 537 36
  • Android OpenGL ES抗锯齿

    多重采样MSAA GLSurfaceView设置多重采样 抗锯齿EGLConfigChooser author weiss email kleinminamo gmail com created 2018 7 3 public class
  • Quartz2.2.0 产生misfire条件参数misfireThreshold和misfire策略详细说明

    首先 misfire产生的条件是 misfire的时间间隔大于配置里设置的misfireThreshold值 就认为是misfire了 错失触发了 比如 13 07 24开始执行 重复执行5次 开始执行时 quartz已经计算好每次调度的时