spring quartz定时任务

问题描述:

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

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

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

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

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

[code="java"]

[/code]

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

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

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

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

你可以参考[url=http://static.springsource.org/spring/docs/2.5.x/reference/scheduling.html]标准文档[/url]

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

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

[quote]By default, Quartz Jobs are stateless, resulting in the possibility of jobs interfering with each other. If you specify [color=red]two triggers for the same JobDetail[/color], 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.[/quote]

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