• Quartz.NET ScheduledFireTimeUtc 当超过1分钟时出现的问题。


    验证代码:

     1     class Program
     2     {
     3         public static IScheduler scheduler = null;
     4         static void Main(string[] args)
     5         {
     6             scheduler = StdSchedulerFactory.GetDefaultScheduler();
     7             scheduler.Start();
     8             string GroupName = "DateRules";
     9             string RunCorn = "0 " + DateTime.Now.AddMinutes(1).Minute + " * * * ?";
    10             for (int i = 0; i < 30; i++)
    11             {
    12                 string Identity = "DataRule_" + i;
    13 
    14                 JobDataMap JobData = new JobDataMap();
    15                 JobData["Index"] = i;
    16                 IJobDetail job = JobBuilder.Create<MyJob>()
    17                    .WithIdentity(Identity, GroupName)
    18                    .SetJobData(JobData)
    19                    .Build();
    20 
    21                 ITrigger trigger = TriggerBuilder.Create()
    22                     .WithIdentity(Identity, Identity)
    23                     .WithCronSchedule(RunCorn)
    24                     .Build();
    25 
    26                 scheduler.ScheduleJob(job, trigger);
    27             }
    28             Console.ReadLine();
    29         }
        public class MyJob : IJob
        {
            public void Execute(IJobExecutionContext context)
            {
                var FireTimeAfter = context.Trigger.GetFireTimeAfter(context.ScheduledFireTimeUtc.Value.ToLocalTime());
            
    string Index = context.JobDetail.JobDataMap["Index"].ToString(); Thread.Sleep(30000); Console.WriteLine( FireTimeAfter.Value.ToLocalTime() + " " + context.ScheduledFireTimeUtc.Value.ToLocalTime() + " " + Index); } }

    quartz本身包含一个线程池,让线程池中所有线程都Sleep30秒后输出ScheduledFireTimeUtc为示例:2019-09-17 09:00:00 ,当Sleep超过1分钟再启动的Job的ScheduledFireTimeUtc变为了:2019-09-17 09:01:00 

    这时使用使用GetFireTimeAfter重新取得应执行时间。

  • 相关阅读:
    关于Linux测试题
    Linux常用命令按功能统一总结
    关于Eclipse的Save时的自定义操作
    关于产品版本英语缩写
    关于location.href几种用法的区别
    关于Java多态的总结.
    关于JDK中正则表达式
    关于JDK中的集合总结(三)
    关于JDK中的集合总结(二)
    关于JDK中的集合总结(一)
  • 原文地址:https://www.cnblogs.com/jgjgjg23/p/11531778.html
Copyright © 2020-2023  润新知