【发布时间】:2014-07-03 19:51:35
【问题描述】:
我想要实现的目标: 我有一个第二触发器,每 5 秒触发一次,有状态的作业,有时需要超过 5 秒(例如 7 秒),而我现在拥有的
start: 00:00:00
end : 00:00:07
start: 00:00:07 < right after previous has finished
我想要什么:
start: 00:00:00
it should run at 00:00:05 but it hasn't
end : 00:00:07
start: 00:00:10 (5 seconds after previous, successive or not)
我已经尝试了quartz.net 版本 2 和 1。
工作:
[PersistJobDataAfterExecution]
[DisallowConcurrentExecution]
public class StatefulJob : IJob (or IStatefulJob in 1.x version)
{
public void Execute(IJobExecutionContext context)
{
Console.WriteLine("StateFull START " + DateTime.Now.ToString());
Thread.Sleep(7000);
Console.WriteLine("StateFull END " + DateTime.Now.ToString());
}
}
触发器:
var trigger1 = TriggerBuilder
.Create()
.WithSimpleSchedule(x =>
x.WithIntervalInSeconds(timeout)
.RepeatForever()
.Build();
编辑
我曾尝试使用WithMisfireHandlingInstructionIgnoreMisfires(),但由于调度程序被关闭,或者因为没有可用的线程而发生失败,在我的情况下 - 因为我使用 StatefulJob,作业没有执行。也许我错了,但行为保持不变。
EDIT2 好的,带有“正在运行”标志的解决方案在单线程应用程序中非常有效。但是,如果我在几个线程(使用不同的参数)中运行这项工作,它就行不通 那么,是否有可能使用石英实现我想要的行为?
【问题讨论】:
-
.WithMisfireHandlingInstructionIgnoreMisfires() 做你想做的事吗?
-
我已经尝试过了,但是由于调度程序被关闭,或者因为没有可用的线程而发生了失败,在我的情况下 - 作业没有执行,因为我使用 StatefulJob (实际上我设置了 attr - DisallowConcurrentExecution) .也许我错了,但行为保持不变。
标签: quartz-scheduler quartz.net quartz.net-2.0