• 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重新取得应执行时间。

  • 相关阅读:
    VMware虚拟机的三种连接方式
    Codeblocks16.01配置wxWidgets3.0.4
    DAO编程(VC6.0中的应用)
    VC++ 中用ado连接数据库
    C中文件的输入输出与C++的文件流
    Cpp中流继承关系
    a标签置灰不可点击
    手动操作数据库
    $.ajaxFileUpload is not a function
    【工具】手机号码、电话号码正则表达式
  • 原文地址:https://www.cnblogs.com/jgjgjg23/p/11531778.html
Copyright © 2020-2023  润新知