如何使Quartz.NET流程同步? [英] How to make Quartz.NET process synchronously?

查看:254
本文介绍了如何使Quartz.NET流程同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个计划作业有重复间隔每5分钟进行。它的正常工作。

不过,我有一个情况在我的第一份工作是没有完成的5分钟,第二份工作开始(因为它定于5分钟)。

我不想这样做,只有一个作业应该在同一时间内工作。我该怎么办呢?

这是我的code:

  ISchedulerFactory schedFact =新StdSchedulerFactory();
IScheduler sched的= schedFact.GetScheduler();
触发emailTrigger = TriggerUtils.MakeMinutelyTrigger(5);
emailTrigger.StartTimeUtc = TriggerUtils.GetEvenMinuteDate(DateTime.UtcNow);
emailTrigger.Name =EmailTrigger;
的JobDetail emailJobDetail =新的JobDetail(EmailJob,空的typeof(EmailJob));
sched.ScheduleJob(emailJobDetail,emailTrigger);
sched.Start();
 

解决方案

我用Quartz.net了一下,但从来没有研究工作的执行串行处理。从我的经验,石英是更适用于水货预定处理,在那里工作可以重叠,如果他们运行长,所以我不知道它是否支持你所需要的。

有一个简单的解决问题的方法可能是使用可以由任何工作线程(如锁,互斥,信号量,或全球布尔等)访问的同步变量。当一个新的工作启动时,它应该检查锁,如果它是免费的,抓住它,并保持它,直到它完成。如果高就醒来,并看到一个previous作业仍在运行,新的工作正好可以退出,等待调度再次尝试在接下来的时间间隔。你也可以有新的工作等待previous来完成的,但如果你这样做,你运行的作业堆积如山等待执行的风险,系统永远不会迎头赶上。

I have a scheduled job that have repeat interval for every 5 mins. It's working fine.

But I have a situation in where my first job is not completing in 5 mins and a second job is starting (as it scheduled for 5 mins).

I don't want to do that, only one job should be working at a time. How can I do that?

This is my code:

ISchedulerFactory schedFact = new StdSchedulerFactory();
IScheduler sched = schedFact.GetScheduler();
Trigger emailTrigger = TriggerUtils.MakeMinutelyTrigger(5);
emailTrigger.StartTimeUtc = TriggerUtils.GetEvenMinuteDate(DateTime.UtcNow);
emailTrigger.Name = "EmailTrigger";
JobDetail emailJobDetail = new JobDetail("EmailJob", null, typeof(EmailJob));
sched.ScheduleJob(emailJobDetail, emailTrigger);
sched.Start();

解决方案

I've used Quartz.net a bit, but never investigated enforcing serial processing between jobs. From my experience, Quartz is more intended for "parallel" scheduled processing, where jobs can overlap if they run long, so I'm not sure if it supports what you need.

A simple solution to your problem might be to use a synchronization variable that can be accessed by any of the job threads (e.g. a lock, mutex, semaphore, or global boolean, etc.). When a new job starts up, it should check the lock, and if it's free, grab it, and hold it until it's finished. If another job wakes up, and sees that a previous job is still running, the new job can just exit, and wait for the scheduler to try again on the next interval. You could also have the new job wait for the previous to finish, but if you do that, you run the risk of jobs piling up waiting to execute, and the system never "catching up."

这篇关于如何使Quartz.NET流程同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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