Java 如何将 QUARTZ 作业设置为仅在另一个作业完成、停止时启动?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22861365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set to a QUARTZ JOB to start only when an another JOB finished, stopped?
提问by victorio
I have a QUARTZ JOB which is starts every 10 minutes.
我有一个 QUARTZ 作业,它每 10 分钟启动一次。
If a JOB doesn't finish in 10 minutes, in the next 10th minute another JOB will start.
如果一个 JOB 没有在 10 分钟内完成,在接下来的 10 分钟内另一个 JOB 将开始。
What I want is: the next JOB (after every 10 minute) should start only, if the previous JOB has finished running. Is there any way to do it?
我想要的是:如果前一个作业已完成运行,则下一个作业(每 10 分钟后)才应开始。有什么办法吗?
采纳答案by M.Faizal
@DisallowConcurrentExecution is an annotation that can be added to the Job class that tells Quartz not to execute multiple instances of a given job definition (that refers to the given job class) concurrently. Notice the wording there, as it was chosen very carefully. In the example from the previous section, if "SalesReportJob" has this annotation, than only one instance of "SalesReportForJoe" can execute at a given time, but it can execute concurrently with an instance of "SalesReportForMike". The constraint is based upon an instance definition (JobDetail), not on instances of the job class. However, it was decided (during the design of Quartz) to have the annotation carried on the class itself, because it does often make a difference to how the class is coded.
@DisallowConcurrentExecution 是一个注解,可以添加到 Job 类中,它告诉 Quartz 不要同时执行给定作业定义(指给定作业类)的多个实例。注意那里的措辞,因为它是非常仔细地选择的。在上一节的示例中,如果“SalesReportJob”具有此注释,则在给定时间只能执行一个“SalesReportForJoe”实例,但它可以与“SalesReportForMike”实例同时执行。该约束基于实例定义 (JobDetail),而不是基于作业类的实例。然而,(在 Quartz 的设计期间)决定在类本身上进行注释,因为它通常会对类的编码方式产生影响。
If you dont want SalesReportForMike and SalesReportForJoe to run concurrently ,then you can set the scheduler's ThreadPool size to 1. So at any given time only one job will run.
如果您不希望 SalesReportForMike 和 SalesReportForJoe 同时运行,那么您可以将调度程序的 ThreadPool 大小设置为 1。这样在任何给定时间只会运行一个作业。
Also take a look at StatefulJob
还可以看看StatefulJob
回答by Martin
Take a look at the DisallowConcurrentExecutionannotation which will prevent multiple instances of the same job to run at the same time.
查看DisallowConcurrentExecution注释,它会阻止同一作业的多个实例同时运行。