【常见错误】Quartz常见错误
1.集群之后把其中一个Quartz服务停了,其他的也不接手工作
问题描述
集群之后,A节点执行了大多数任务,B节点大部分时间处于空闲,停掉A节点,B节点也不会接手工作。
解决方式
修改Quartz的配置,将每个节点的org.quartz.scheduler.instanceId设置为不同的值,或者都设置为AUTO。另外org.quartz.jobStore.isClustered属性必须设为true,org.quartz.jobStore.clusterCheckinInterval属性为集群中每次检查的时间间隔(按我的理解,应该差不多等于一个服务器挂了之后,其他服务器接手的时间),单位为毫秒,默认值是15000。
2.在Spring中使用Quartz的高级配置
问题描述
Quartz集群仅能使用JDBC JobStore工作,需要在Spring中使用Quartz的高级配置
解决方式
1 通过SchedulerFactoryBean的configLocation属性指定Quartz配置文件的位置。
<bean id="quartzJobFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="clusterTesterJobScheduledTask" />
</list>
</property>
<property name="configLocation" value="classpath:quartz.properties" />
</bean>
2 通过SchedulerFactoryBean的quartzProperties属性直接配置
3.NotSerializableException
问题描述
在将Quartz的Job持久化到数据库的过程中产生NotSerializableException。详细异常信息为:
java.io.NotSerializableException: Unable to serialize JobDataMap for insertion into database because the value of property 'methodInvoker' is not serializable: org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean
解决方式
将任务class MethodInvokingJobDetailFactoryBean 替换为 JobDetailFactoryBean
<!-- 任务 -->
<bean id="oaBranchDataCacheJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="group" value="ETC_REST_GROUP" />
<property name="name" value="OaBranchDataCacheJob" />
<!-- 没有绑定触发器仍然保留在Quartz的JobStore中 -->
<!-- <property name="Durability" value="true"/> -->
<property name="jobClass" value="com.c2vm.xia.rest.quartz.job.OaBranchDataCacheJob" />
</bean>
<!-- 调度触发器 -->
<bean id="oaBranchDataCacheJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="group" value="ETC_REST_GROUP" />
<property name="name" value="OaBranchDataCacheJob_trigger" />
<property name="jobDetail" ref="oaBranchDataCacheJob" />
<property name="cronExpression" value="0/5 * * * * ?" />
</bean>
并修改任务Java类继承QuartzJobBean
import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
public class OaBranchDataCacheJob extends QuartzJobBean {
private Logger logger = Logger.getLogger(OaBranchDataCacheJob.class);
public OaBranchDataCacheJob() {
logger.info("OaBranchDataCacheJob init ..");
}
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
System.out.println("=======【OaBranchDataCacheJob】");
}
}
4.持久化时jobDetail找不到
问题描述
错误信息如下:
org.quartz.JobPersistenceException: The job (DEFAULT.studyDetail) referenced by the trigger does not exist.
解决方式
原因一般是数据源配置导致的问题。
可能的原因是:数据源未配置成自动提交,当第一次启动trigger时,之前对数据库的job的增加的事物没有自动提交,导致后面的事物无法查询到。
如果数据源是通过dbcp配置的将自动提交配置为true
<property name="defaultAutoCommit" value="false" />
如果是c3p0配置为
autoCommitOnClose=true
5.错误Jobs added with no trigger must be durable
问题描述
启动时报错
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schedulerFactoryBean' defined in ServletContext resource [/WEB-INF/conf/spring-quartz.xml]: Invocation of init method failed; nested exception is org.quartz.SchedulerException: Jobs added with no trigger must be durable.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:610)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4738)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5181)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.quartz.SchedulerException: Jobs added with no trigger must be durable.
at org.quartz.core.QuartzScheduler.addJob(QuartzScheduler.java:934)
at org.quartz.core.QuartzScheduler.addJob(QuartzScheduler.java:927)
at org.quartz.impl.StdScheduler.addJob(StdScheduler.java:268)
at org.springframework.scheduling.quartz.SchedulerAccessor.addJobToScheduler(SchedulerAccessor.java:344)
at org.springframework.scheduling.quartz.SchedulerAccessor.addTriggerToScheduler(SchedulerAccessor.java:367)
at org.springframework.scheduling.quartz.SchedulerAccessor.registerJobsAndTriggers(SchedulerAccessor.java:305)
at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:508)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
... 21 more
解决方式
在配置文件中的jobDetail bean配置里增加配置

<!-- 没有绑定触发器仍然保留在Quartz的JobStore中 --> <property name="Durability" value="true"/>
6.JobStoreCMT发生死锁
解决方式
1.当tx需要很长的时间时,某些数据库可能会误报死锁,可以加索引
// 创建单列索引
在qrtz_triggers(NEXT_FIRE_TIME)上创建索引idx_qrtz_t_next_fire_time;
在qrtz_triggers(TRIGGER_STATE)上创建索引idx_qrtz_t_state;
在qrtz_triggers(TRIGGER_STATE,NEXT_FIRE_TIME)上创建索引idx_qrtz_t_nf_st;
在qrtz_fired_triggers(TRIGGER_NAME)上创建索引idx_qrtz_ft_trig_name;
在qrtz_fired_triggers(TRIGGER_GROUP)上创建索引idx_qrtz_ft_trig_group;
在qrtz_fired_triggers(TRIGGER_NAME)上创建索引idx_qrtz_ft_trig_name;
在qrtz_fired_triggers(INSTANCE_NAME)上创建索引idx_qrtz_ft_trig_inst_name;
在qrtz_fired_triggers(JOB_NAME)上创建索引idx_qrtz_ft_job_name;
在qrtz_fired_triggers(JOB_GROUP)上创建索引idx_qrtz_ft_job_group;
// 创建联合索引
创建索引idx_qrtz_ft_trig_n_g on \
qrtz_fired_triggers(TRIGGER_NAME,TRIGGER_GROUP);
创建索引idx_qrtz_t_next_fire_time_misfire on \
qrtz_triggers(MISFIRE_INSTR,NEXT_FIRE_TIME);
创建索引idx_qrtz_t_nf_st_misfire on \
qrtz_triggers(MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_STATE);
创建索引idx_qrtz_t_nf_st_misfire_grp on \
qrtz_triggers(MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_GROUP,TRIGGER_STATE);
2.检查数据源中是否有线程池连接数量+2个连接,只能多不能少
3.确保你有一个为Quartz配置的托管和非托管数据源
4.确保您使用调度程序接口完成的所有工作都是在事务中完成的。通过在SessionBean中使用调度程序来完成此操作,该调用程序的tx设置为“Required”和“Container”。或者在具有类似设置的MessageDrivenBean中。最后,自己启动一个UserTransaction,并在完成后提交工作。
5.如果任务的execute()方法使用调度程序,请通过使用UserTransaction或通过设置Quartz config属性“org.quartz.scheduler.wrapJobExecutionInUserTransaction = true”确保事务正在进行中。
7.quartz.properties配置filename
应该是
org.quartz.plugin.jobInitializer.fileNames = my_quartz_jobs.xml
而不是
org.quartz.plugin.jobInitializer.fileName = my_quartz_jobs.xml
这个应该和quartz的jar包版本有关,具体哪个版本使用哪个么有研究。否则会报错
Exception in thread "main" org.quartz.SchedulerException: JobStore SchedulerPlugin 'org.quartz.plugins.xml.JobInitializationPlugin' props could not be configured. [See nested exception: java.lang.NoSuchMethodException: No setter for property 'fileName'] at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:) at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:) at org.quartz.impl.StdSchedulerFactory.getDefaultScheduler(StdSchedulerFactory.java:) at com.gyb.JobScheduler.startScheduler(JobScheduler.java:) at com.gyb.JobScheduler.main(JobScheduler.java:) Caused by: java.lang.NoSuchMethodException: No setter for property 'fileName' at org.quartz.impl.StdSchedulerFactory.setBeanProps(StdSchedulerFactory.java:) at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:) ... more
8.应用服务器启动状态下,当对任务进行了修改时(即修改了job.xml中的任务明细),Quartz无法响应这种变化.也就是说,Quartz并没有进行"有状态"作业!
无论是修改了任务明细中的参数列表--JobDataMap,或是CronExpression中的定时表达式,都应该立即做出响应,并按照新的配置参数去执行这个任务.
解决方式
在quartz.properties中加入下面两行配置即可:
#自动扫描任务单并发现改动的时间间隔,单位为秒 org.quartz.plugin.jobInitializer.scanInterval #覆盖任务调度器中同名的jobDetail,避免只修改了CronExpression所造成的不能重新生效情况 org.quartz.plugin.jobInitializer.overWriteExistingJobs = true
9.任务被删除后,数据库不会减少任务
解决方式
可以考虑在JobDataMap中增加是否执行的配置项,即使任务会执行,但根据这种配置项,仍然可以拒绝下一步的操作.当然了,修改CronExpression使之成为一个永远不会执行到的时间也是一个办法.
或者在数据库中物理删除
【常见错误】Quartz常见错误的更多相关文章
- mysql 常见的几个错误问题
Mysql常见的几个错误问题及解决方法: 1.问题: mysql DNS反解:skip-name-resolve 错误日志有类似警告: 点击(此处)折叠或打开 120119 16:26:04 [War ...
- Java 中最常见的 5 个错误
在编程时,开发者经常会遭遇各式各样莫名错误.近日,Sushil Das 在 Geek On Java上列举了 Java 开发中常见的 5 个错误,与君共「免」. 原文链接:Top 5 Common M ...
- SEO中最常见的几个错误
昨天答应给放点干活的,今天如约而来! SEO中最常见的几个错误: 1.关键词 人们往往想当然的选择自己喜欢的keyword,但用户在搜索时,根本不会使用它们.比方说,你选择"优化果酱&q ...
- Oracle优化网上常见的5个错误观点
最近系统的研究了一下ORACLE SQL语句性能调优,在此大言不惭的得出一个观点——网上很多性能调优的结论都是错误的或者不周全的.现在的DBA大牛些都太低调了,不出来斧正一下,小弟来借这个机会吐槽一下 ...
- 常见C语言编译错误解析【转】
C语言编译错误信息及说明1. 在函数 ‘transform’ 中:7: 错误:expected ‘;’ before ‘{’ token 解释:‘{’之前的某个语句缺少分号‘;’: 2. 在函数 ...
- 常见反编译产生错误 k__BackingField 解决办法
常见反编译产生错误 k__BackingField 解决办法 无聊反编译小蚂蚁出现上千的错同样的错 private bool <EnableRuntimeHandler> ...
- adb使用过程常见的几种错误总结
问题1:Failure [INSTALL_FAILED_ALREADY_EXISTS] 问题原因:该程序已存在. 解决方法:增加-r参数,即可成功覆盖安装 问题2:Failure [INSTALL_F ...
- http常见的5个错误
1. HTTP 500错误(内部服务器错误)对对HTTP 500错误的定义已经充分证明了这是一个最常见的HTTP错误. 一般来说,HTTP 500 错误就是web服务器发生内部错误时返回的信息. 例如 ...
- A query was run and no Result Maps were found for...原来是mapper.xml文件出了问题,是使用MyBatis最常见的一种错误
今天遇到一个问题,原来是mapper.xml文件出了问题,是使用MyBatis最常见的一种错误 报错的结果是这样的: A query was run and no Result Maps were f ...
- 5种常见的Docker Compose错误
在构建一个容器化应用程序时,开发人员需要一种方法来引导他们正在使用的容器去测试其代码.虽然有几种方法可以做到这一点,但 Docker Compose 是最流行的选择之一.它让你可以轻松指定开发期间要引 ...
随机推荐
- java的Io流学习
Java中io流的学习(一)File:https://blog.csdn.net/qq_41061437/article/details/81672859 Java中io流的学习(二)FileInpu ...
- sublime插件之px转rem
sublime插件之px转rem 安装: 1.下载sublime并安装: 2.下载cssrem:https://github.com/hyb628/cssrem: 3.找到 Packages (首 ...
- js运用2
1.变量提升 变量提升是浏览器的一个功能,在运行js代码之前,浏览器会给js一个全局作用域叫window,window分两个模块,一个叫内存模块,内存模块找到当前作用域下的所有的带var和functi ...
- 公众号对接绑定视频教程<推荐>【申明:来源于网络】
公众号对接绑定视频教程<推荐>[申明:来源于网络] 地址: http://www.456wx.com/bbs/thread-123-1-1.html
- [Day10]继承、抽象类
1.继承:在一个现有类的基础上去构建一个新的类,构建出来的新类被称为子类,现有类被称作父类,子类会自动拥有父类所有可继承的属性和方法. 2.继承的格式 : class 子类 extends 父类{} ...
- LeetCode 448 Find All Numbers Disappeared in an Array 解题报告
题目要求 Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice a ...
- java框架之Hibernate(4)-几种检索方式
准备 模型及映射文件 package com.zze.bean; import java.util.HashSet; import java.util.Set; public class Class ...
- [摘抄] Bezier曲线、B样条和NURBS
Bezier曲线.B样条和NURBS,NURBS是Non-Uniform Rational B-Splines的缩写,都是根据控制点来生成曲线的,那么他们有什么区别了?简单来说,就是: Bezier曲 ...
- zabbix-agent 在SElinux Enforcing 状态的文件权限问题及解决办法
因为某种原因必须要开启SElinux,用yum装了一个zabbix-agent 替换了一下配置文件结果悲剧了 # systemctl restart zabbix-agent ● zabbix-age ...
- pandas处理时间序列(2):DatetimeIndex、索引和选择、含有重复索引的时间序列、日期范围与频率和移位、时间区间和区间算术
一.时间序列基础 1. 时间戳索引DatetimeIndex 生成20个DatetimeIndex from datetime import datetime dates = pd.date_rang ...