请教大神 项目中的使用了 spring quartz ,最近一周服务器上的所有定时器在凌晨4点左右开始全部失效 上午10点多又全部恢复正常执行 ,我们的定时设置都是10分钟轮循*******十点左右不用重启服务 什么都不需要操作 就会恢复执行 *******
只能给你几个虑解决问题建议
1)任务执行的时间是否超过任务间隔,10min中一般情况都很难,除非处理千万级别的批处理,如果超过要优化程序
2)观察LOG日志,同时定时批处理任务的启动和结束是否串行执行的,如果串行执行的说明你的配置有问题,executor给少了,我记着默认的好像非常小
3)查找日志异常,是否某些异常情况导致任务终止,你说4点钟到10点钟实效是日志信息没有,还是数据没有,我无法确定
应该是后台业务逻辑的问题吧?quartz框架不会出这样的问题
把代码发出来看看,尤其是时间配置那块
配置
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:component-scan base-package="com.project.controller" />
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
定时器
*
@Scheduled(cron="0 */5 * * * ?")
public void taskCycleMessageGoodsPrice() {
System.out.println("!!!!!!!!!!!!!!!!开始解析京东商品!!!!!!!!!!!!!!!!!!!1");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
long startTime = System.currentTimeMillis();
{
解析代码
}
}
首先检查是否有内存是否未释放或者jvm调优 可以看看 GC回收日志和堆栈信息,
其次建议加一个 ReentrantLock 来保证单位时间未处理完的任务不受影响。
try{
if(lock.tryLock()){
//处理方法
}
}catch(Exception e){
log.error("定时异常", e);
}finally{
if(lock.isHeldByCurrentThread()){
lock.unlock();
}
}
仔细检查下,看看是不是自己那地方弄错了,一般quartz不会有问题啊
定时器
*
@Scheduled(cron="0 */5 * * * ?")
public void taskCycleMessageGoodsPrice() {
System.out.println("!!!!!!!!!!!!!!!!开始解析京东商品!!!!!!!!!!!!!!!!!!!1");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
long startTime = System.currentTimeMillis();
{
解析代码
}
}
启动和结束都加日志看看。同时try catch异常打印出来看看
日志呢,查看下日志文件。quartz应该不会出现这样的问题,有可能是你的代码逻辑有问题