从Quartz中的调度程序获取执行的作业

时间:2013-05-08 07:00:07

标签: quartz-scheduler

我想从Quartz中的调度程序中检索已调度但已执行的作业。有没有办法这样做?

2 个答案:

答案 0 :(得分:2)

嗯,首先您需要检索所有当前预定作业的列表:

Scheduler sched = new StdSchedulerFactory().getScheduler();
List jobsList = sched.getCurrentlyExecutingJobs();

然后,这是迭代列表以检索到达作业的上下文的问题。每个上下文都有一个getPreviousFireTime()。

Iterator jobsIterator = jobsList.listIterator();   
List<JobExecutionContext> executedJobs = new List<JobExecutionContext>();  

while(jobsIterator.hasNext())
{
    JobExecutionContext context = (JobExecutionContext) jobsIterator.next();
    Date previous = context.getPreviousFireTime();
    if (previous == null) continue; //your job has not been executed yet

    executedJobs.Add(context); //there's your list!
}

根据您使用的石英(java或.net),实现可能略有不同,但原理是相同的。

答案 1 :(得分:0)

设置属性JobDetail.setDurability(true) - 指示Quartz在成为&#34; orphan&#34;时不要删除它。 (当Job不再有引用它的Trigger时)。