zoukankan      html  css  js  c++  java
  • 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);
    }

    每一份坚持,以后都会有收获
  • 相关阅读:
    03 java中的基本数据类型和运算符
    02 Eclipse安装
    01 HelloWorld
    express不是内部或外部命令
    win10 内存或系统资源不足,无法打开PPT
    win 10中解决“此文件在另外一个进程中运行”的问题
    后台查找密码暴力破解
    DVWA--全等级暴力破解(Burte Force)
    DVWA简单搭建
    破解版
  • 原文地址:https://www.cnblogs.com/wilsons/p/10737063.html
Copyright © 2011-2022 走看看