在使用Quartz.NET的时候可能会碰到这样一种情况,多个触发器触发同一个任务时,当多个触发器触发的时间相互冲突时,也就是在同一时间触发同一个任务,这时候就需要有一个触发的优先级了,即由哪个触发器来触发,如果不设置优先级的话,Quartz.NET会按照默认的方式处理。设置优先级的代码如下:
public class TriggerEchoJob : IJob
{
private ILog log = LogManager.GetLogger(typeof (TriggerEchoJob));
public void Execute(IJobExecutionContext context)
{
log.Info("触发器: " + context.Trigger.Key);
}
}
public class PriorityExample
{
public static void Run()
{
ILog log = LogManager.GetLogger(typeof (PriorityExample));
NameValueCollection properties = new NameValueCollection();
properties["quartz.scheduler.instanceName"] = "PriorityExampleScheduler";
properties["quartz.threadPool.threadCount"] = "1";
properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";

本文介绍如何在Quartz.NET中设置触发器的执行优先级,以解决多个触发器同时触发同一任务时的冲突问题。在不设置优先级的情况下,Quartz.NET将按默认策略处理。通过代码示例展示了设置优先级的方法。
最低0.47元/天 解锁文章
661

被折叠的 条评论
为什么被折叠?



