Quartz Spring CronTrigger 触发次数超过配置次数
我有一个用于作业“digestJob”的 cronTrigger:
<bean id="digestCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="digestJob" />
<property name="cronExpression" value="0 35 15 * * ?" />
</bean>
这是我的 SchedulerFactoryBean 配置:
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="digestCronTrigger" />
</list>
</property>
</bean>
问题是,digestCronTrigger 应该每天下午 5:35 触发一次,但它在指定时间被触发两次。但是,当我使用 SimpleTrigger 时:
<bean id="digestTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="digestJob" />
<property name="startDelay" value="0" />
<property name="repeatInterval" value="10000" />
</bean>
一切正常,并且触发器每 10 秒触发一次。为什么digestCronTrigger被触发两次?我的 cron 表达式有问题吗,或者我缺少任何属性吗?任何帮助将不胜感激。
I have a cronTrigger for a job "digestJob":
<bean id="digestCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="digestJob" />
<property name="cronExpression" value="0 35 15 * * ?" />
</bean>
Here is my schedulerFactoryBean configuration:
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="digestCronTrigger" />
</list>
</property>
</bean>
The problem is, the digestCronTrigger is supposed to be fired ONCE everyday at 5:35 PM, but it is being fired TWICE at the specified time. However, when I use SimpleTrigger:
<bean id="digestTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="digestJob" />
<property name="startDelay" value="0" />
<property name="repeatInterval" value="10000" />
</bean>
everything works fine and the trigger is fired exactly once every 10 seconds. Why digestCronTrigger is being fired twice? Is there something wrong with my cron expression, or is there any property that I am missing? Any help will be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我在 springsource 论坛上发布了 同样的问题,在那里我得到了帮助来找出原因问题背后:
我加载应用程序上下文两次。后来我从这篇文章中找到了如何避免加载上下文两次。现在一切进展顺利。
I posted same question at springsource forums where I got help to figure out the cause behind the problem:
I was loading the application context twice. Later I found from this post how to avoid loading the context twice. Now things are working fine.
如果您在启动应用程序时创建触发器并在quartz.properties 文件中使用数据源,也可能会发生这种情况。每次启动服务器时,它都会向
QRTZ_CRON_TRIGGERS
和QRTZ_TRIGGERS
表写入一个新触发器,并在每次重新启动时使用所有触发器。This can also happen if you're creating a trigger when you're starting your application and are using a datasource in your quartz.properties file. Every time you start your server it will write a new trigger to the
QRTZ_CRON_TRIGGERS
andQRTZ_TRIGGERS
tables and use all of them on each restart.试试这个:
Try this:
我也遇到这个问题,终于找到根本原因了。
我们的服务器 Tomcat 设置存在一些问题
/.../Tomcat/conf/server.xml
我们的
server.xml
如下所示,同一个tomcat中有2个
定期运行相同的cronJob,但写入相同的日志文件和 db 同时,所以它按计划触发两次,但如果我们手动运行 cronjob,它只会触发一次......解决方案当然是删除一台主机,希望这能有所帮助
I also have this issue and we finally found the root cause.
There is some problem in our server Tomcat setting
/.../Tomcat/conf/server.xml
Our
server.xml
looks like below, There is 2<Host>
in the same tomcat that run the same cronJob regularly, but writing to the same log file and db at same time, so it fires two times by schedule, but if we run cronjob manually, it only fire once...The solution, of course, is to remove one Host, hope this help