如何做“顺序”作业调度(Quartz?) [英] How to do “sequential” Job Scheduling (Quartz?)

查看:545
本文介绍了如何做“顺序”作业调度(Quartz?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Quartz Scheduling,有2个工作。第一个作业执行约2分钟的任务,第二个作业是为临时文件的清理操作设置。所以,我需要设置Schedule以一种方式工作,即在第一个作业执行/完成执行任务后,我需要在Second Job的帮助下进行清理操作。


考虑示例9 - Quartz 2.1.x下的Job Listeners,它声明我们可以定义一个名为jobWasExecuted(_,_)的方法;在Job Listener中,它在第一个作业执行/或进入运行状态时执行。


我们是否能够设置可以收听第一份工作然后执行第二份工作的时间表?或者,


我们是否能够像在Java多线程中那样定义join()方法,它可以在完成第一个作业时执行?

I'm making use of Quartz Scheduling and there are 2 jobs. First Job is performing the tasks for around 2 minutes and the Second one is to be setup for Cleaning Operations of Temporary Files. So, I need to setup the Schedule to work in a way that after the first job is executed/finished performing tasks I need to do the cleaning operations with the help of Second Job.
Considering the Example 9 - Job Listeners under Quartz 2.1.x which states that we can define a method named jobWasExecuted( _, _ ); in the Job Listener and it executes when the 1st job is executed/or comes in running state.
Are we able to setup the schedule which can listen for the first job finishing then executes second? or,
Are we able to define the join() method like in Java Multithreading which can execute on the completion of first job?

推荐答案


目前没有直接或免费的方式来链接触发器
Quartz。但是,有几种方法可以在没有
努力的情况下完成它。下面是两种方法的概述:

There currently is no "direct" or "free" way to chain triggers with Quartz. However there are several ways you can accomplish it without much effort. Below is an outline of a couple approaches:

一种方法是使用一个可以注意到完成的侦听器(即TriggerListener,JobListener或
SchedulerListener)一个作业/触发器和
然后立即安排一个新的触发器来触发。这种方法可能会涉及
,因为你必须通知听众哪个工作
跟随哪个 - 你可能需要担心这个
信息的持久性。

One way is to use a listener (i.e. a TriggerListener, JobListener or SchedulerListener) that can notice the completion of a job/trigger and then immediately schedule a new trigger to fire. This approach can get a bit involved, since you'll have to inform the listener which job follows which - and you may need to worry about persistence of this information.

另一种方法是构建一个Job,它在JobDataMap中包含要触发的下一个作业的名称,并在作业完成时(其Execute()的最后一步)方法)让工作安排下一份工作。有几个人这样做,并且运气好。大多数人都创建了一个基类(抽象)类,它是一个知道如何使用特殊键(常量)从JobDataMap中获取作业名称和组的Job,并包含用于调度已识别作业的代码。然后
他们只是扩展这个类,其中包括工作应该做的额外的
工作。

Another way is to build a Job that contains within its JobDataMap the name of the next job to fire, and as the job completes (the last step in its Execute() method) have the job schedule the next job. Several people are doing this and have had good luck. Most have made a base (abstract) class that is a Job that knows how to get the job name and group out of the JobDataMap using special keys (constants) and contains code to schedule the identified job. Then they simply make extensions of this class that included the additional work the job should do.

参考: http://www.quartz-scheduler.net/documentation/faq.html#how-do-i-chain-job-execution?-or,-how-do-i-create- a-workflow

这篇关于如何做“顺序”作业调度(Quartz?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆