• quartz.net 任务调度分布式,动态添加(1)


    try
    {
    //1.首先创建一个作业调度池
    var properties = new NameValueCollection();

    properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
    properties["quartz.threadPool.threadCount"] = "10";
    properties["quartz.threadPool.threadPriority"] = "Normal";

    //存储类型
    properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";

    //驱动类型
    properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz"; //数据源名称
    properties["quartz.jobStore.dataSource"] = "myDS";

    //连接字符串
    properties["quartz.dataSource.myDS.connectionString"] = @"server=.;Initial Catalog=quartz;Integrated Security=True";
    //sqlserver版本
    properties["quartz.dataSource.myDS.provider"] = "SqlServer-20";

    //是否集群
    properties["quartz.jobStore.clustered"] = "true";
    properties["quartz.scheduler.instanceId"] = "AUTO";

    var factory = new StdSchedulerFactory(properties);

    IScheduler scheduler = factory.GetScheduler();

    scheduler.Start();
    ISchedulerFactory schedFact = new StdSchedulerFactory(properties);
    IScheduler sched = schedFact.GetScheduler();
    var jobKey = JobKey.Create("myjob1", "group");

    if (sched.CheckExists(jobKey))
    {
    Console.WriteLine("当前job已经存在,无需调度:{0}", jobKey.ToString());
    }
    else
    {
    IJobDetail job = JobBuilder.Create<HelloJob>()
    .WithDescription("使用quartz进行持久化存储")
    .StoreDurably()
    .RequestRecovery()
    .WithIdentity(jobKey)
    .UsingJobData("count", 1)
    .Build();

    var trigger = TriggerBuilder.Create()
    .WithIdentity("myjob1", "group")
    .WithCronSchedule("/10 * * * * ?")
    .Build();
    //ITrigger trigger = TriggerBuilder.Create().WithSimpleSchedule(x => x.WithIntervalInSeconds(2).RepeatForever()).Build();

    sched.ScheduleJob(job, trigger);

    Console.WriteLine("调度进行中!!!");
    }
    }
    catch (SchedulerException se)
    {
    Console.WriteLine(se);
    }

    每一份坚持,以后都会有收获
  • 相关阅读:
    关于数据结构的建立
    让背景居中
    亲,你还在使用IE6吗?你 OUT 了!
    ASP 编程 防止字符编码出现乱码的最佳办法
    asp无组件上传图片 动态保存文件名 upload.inc逐句翻译
    微信小程序 textarea 简易解决方案
    PHP ckeditor富文本编辑器 结合ckfinder实现图片上传功能
    PHP 苹果消息推送
    PHP短信发送服务 youe短信企业服务
    c#简单易用的短信发送服务 悠逸企业短信服务
  • 原文地址:https://www.cnblogs.com/wilsons/p/10737063.html
Copyright © 2020-2023  润新知