【quartz】 数据库方式管理任务
2015-06-30 15:15
666 查看
public static void Run(bool inClearJobs, bool inScheduleJobs) { var properties = new NameValueCollection(); properties["quartz.scheduler.instanceName"] = "测试任务"; //调度标识名 集群中每一个实例都必须使用相同的名称 properties["quartz.scheduler.instanceId"] = "instance_one"; //ID设置为自动获取 每一个必须不同 properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz"; properties["quartz.threadPool.threadCount"] = "2";//线程数量 properties["quartz.threadPool.threadPriority"] = "Normal";//线程优先级 properties["quartz.jobStore.misfireThreshold"] = "60000"; //容许的最大作业延长时间 properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";//AdoJobStore properties["quartz.jobStore.useProperties"] = "false";//设置为TRUE不会出现序列化非字符串类到 BLOB 时产生的类版本问题 properties["quartz.jobStore.dataSource"] = "default";//数据库别名 随便取 properties["quartz.jobStore.tablePrefix"] = "QRTZ_";//指定所使用的数据库表前缀 properties["quartz.jobStore.clustered"] = "true";//加入集群 properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz";//数据库类型 properties["quartz.dataSource.default.connectionString"] = @"Server=10.32.11.23,14339;database=YintaiService;uid=erpdev;pwd=Test_2jaJk)@aA2";//数据库配置连接串 properties["quartz.dataSource.default.provider"] = "SqlServer-20";// framework2.0以上 ISchedulerFactory sf = new StdSchedulerFactory(properties); IScheduler sched = sf.GetScheduler(); if (inClearJobs) { sched.Clear();//清除数据 } //注入一个任务 //jobdatamap可以持久化到数据库,但是在运行期间改变了jobdatamap中的某个属性时,这个新值不能持久化到数据库,也就等于是没法修改。 if (inScheduleJobs) { string schedId = sched.SchedulerInstanceId; int count = 1; IJobDetail job = JobBuilder.Create<HelloJob>() .WithIdentity("job_" + count, schedId) // put triggers in group named after the cluster node instance just to distinguish (in logging) what was scheduled from where .RequestRecovery() // ask scheduler to re-execute this job if it was in progress when the scheduler went down... .Build(); ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create() .WithIdentity("triger_" + count, schedId) .StartAt(DateBuilder.FutureDate(1, IntervalUnit.Second)) .WithSimpleSchedule(x => x.WithRepeatCount(2000).WithInterval(TimeSpan.FromSeconds(2))) .Build(); count++; sched.ScheduleJob(job, trigger); } sched.Start(); }
相关文章推荐
- 清理oracle的归档日志
- 数据库触发联合索引的几个条件
- PostgreSQL安装
- Oracle里面的using作用(用于动态sql绑定参数)
- mysql 锁查看
- mysql5.7二进制包安装
- Oracle创建两表关联查询的视图
- Oracle 监听器日志文件过大导致监听异常
- Oracle 短路评估
- mysql常见错误
- 程序调用存储过程中报错 DB2 SQL Error: SQLCODE=-286, SQLSTATE=42727, SQLERRMC=4096;
- SQL语句优化
- 如何安装独立版的CHM(Oracle Cluster Health Monitor)
- REDIS 高可用性部署架构图
- jdbc读取新插入Oracle数据库Sequence值的5种方法
- mysql因为掉电,导致不同步的恢复
- Oracle 字符串处理
- sql中视图的概念
- keepalived+Mysql切换
- ORACLE 视图的 with check option