0 0

spring quartz定时任务15

本人有一个应用,需要 每15分钟 执行一次入库操作(比较费时),使用spring 架构。现在想使用quartz来定时此操作。

我的问题是,如果15分钟后,我的定时任务还没有执行完,该怎么办呢。

希望大家给点建议。非常感谢!

问题补充:
beneo 写道
引用

如果15分钟后,我的定时任务还没有执行完,该怎么办呢。


spring里面有1个选项,表示是否并行

<property name="concurrent" value="false" />


如果是false,那么任务之间不能并行。

意思是:
1. 如果你是CronTriggerBean,比如每刻钟执行一次——你0分执行第一次,结果20分才执行完,那么它第30分才执行第二次。

2. 如果你SimpleTriggerBean,比如说每隔15分钟执行一次——你0分执行了第一次,如果20分钟执行完,那么它会立刻执行第二次

如果是true的话,就反过来。

你可以参考标准文档

beneo 写道
引用

如果15分钟后,我的定时任务还没有执行完,该怎么办呢。


spring里面有1个选项,表示是否并行

<property name="concurrent" value="false" />


如果是false,那么任务之间不能并行。

意思是:
1. 如果你是CronTriggerBean,比如每刻钟执行一次——你0分执行第一次,结果20分才执行完,那么它第30分才执行第二次。

2. 如果你SimpleTriggerBean,比如说每隔15分钟执行一次——你0分执行了第一次,如果20分钟执行完,那么它会立刻执行第二次

如果是true的话,就反过来。

你可以参考标准文档

那个配置,是不是在:一个任务配置在两个TriggerBean里才起作用的啊。
也就是:有两个TriggerBean,他们配置了同一个任务,这样可以用concurrent来控制是否允许他们并发。

问题补充:
beneo 写道
引用

有两个TriggerBean,他们配置了同一个任务,这样可以用concurrent来控制是否允许他们并发。


你这句话说对了一半,
引用
two triggers for the same JobDetail
,意思两个TriggerBean是这样,你一个TriggerBean,被trigger了2次,也是这样



嗯,明天测试一下看,谢谢!如果concurrent设置为false可以解决问题的话,采纳为答案了。

问题补充:
beneo 写道
引用
By default, Quartz Jobs are stateless, resulting in the possibility of jobs interfering with each other. If you specify two triggers for the same JobDetail, it might be possible that before the first job has finished, the second one will start. If JobDetail classes implement the Stateful interface, this won't happen. The second job will not start before the first one has finished. To make jobs resulting from the MethodInvokingJobDetailFactoryBean non-concurrent, set the concurrent flag to false.


注意红色的部分。后面的job,你知道trigger一次就产生一个job,所以跟你的bean有多少个是无关的。


好的,Trigger一次就产生一个job的话,那么concurrent设为false应该就可以了。明天上班的时候测试了。谢谢!
2010年11月28日 13:33

3个答案 按时间排序 按投票排序

0 0

采纳的答案

引用

如果15分钟后,我的定时任务还没有执行完,该怎么办呢。


spring里面有1个选项,表示是否并行

<property name="concurrent" value="false" />


如果是false,那么任务之间不能并行。

意思是:
1. 如果你是CronTriggerBean,比如每刻钟执行一次——你0分执行第一次,结果20分才执行完,那么它第30分才执行第二次。

2. 如果你SimpleTriggerBean,比如说每隔15分钟执行一次——你0分执行了第一次,如果20分钟执行完,那么它会立刻执行第二次

如果是true的话,就反过来。

你可以参考标准文档

2010年11月28日 16:30
0 0

引用
By default, Quartz Jobs are stateless, resulting in the possibility of jobs interfering with each other. If you specify two triggers for the same JobDetail, it might be possible that before the first job has finished, the second one will start. If JobDetail classes implement the Stateful interface, this won't happen. The second job will not start before the first one has finished. To make jobs resulting from the MethodInvokingJobDetailFactoryBean non-concurrent, set the concurrent flag to false.


注意红色的部分。后面的job,你知道trigger一次就产生一个job,所以跟你的bean有多少个是无关的。

2010年11月28日 19:49
0 0

引用

有两个TriggerBean,他们配置了同一个任务,这样可以用concurrent来控制是否允许他们并发。


你这句话说对了一半,
引用
two triggers for the same JobDetail
,意思两个TriggerBean是这样,你一个TriggerBean,被trigger了2次,也是这样

2010年11月28日 19:46

相关推荐

Global site tag (gtag.js) - Google Analytics