Quartz.Net系列(十四):详解Job中两大特性(DisallowConcurrentExecution、PersistJobDataAfterExecution)

1.DisallowConcurrentExceution

从字面意思来看也就是不允许并发执行

简单的演示一下

[DisallowConcurrentExecution] public class TestDisallowConcurrentExectionJob : IJob { public async Task Execute(IJobExecutionContext context) { await Task.Run(() => { var nextTime = context.NextFireTimeUtc?.ToLocalTime(); var currentTime = DateTime.Now; Console.WriteLine($"CurrentTime={currentTime}, FireTime={context.ScheduledFireTimeUtc?.ToLocalTime()}, NextTime={nextTime}"); }); Thread.Sleep(10000); } } public class TestDisallowConcurrentExectionScheduler { public async static Task Test() { var scheduler = await StdSchedulerFactory.GetDefaultScheduler(); await scheduler.Start(); var job = JobBuilder.CreateForAsync<TestDisallowConcurrentExectionJob>() .WithIdentity("TestDisallowConcurrentExectionJob") .UsingJobData("myKey", "myValue") .Build(); var trigger = TriggerBuilder.Create() .WithSimpleSchedule(s => s.WithIntervalInSeconds(1) .RepeatForever()) .Build(); await scheduler.ScheduleJob(job, trigger); } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zyyjgg.html