博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
QuartzNet使用
阅读量:6250 次
发布时间:2019-06-22

本文共 4415 字,大约阅读时间需要 14 分钟。

 

quartz.config# You can configure your scheduler in either 
configuration section# or in quartz properties file# Configuration section has precedencequartz.scheduler.instanceName = RemoteServer# configure thread pool infoquartz.threadPool.type = Quartz.Simpl.SimpleThreadPool, Quartzquartz.threadPool.threadCount = 10quartz.threadPool.threadPriority = Normal# job initialization plugin handles our xml reading, without it defaults are usedquartz.plugin.xml.type = Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz.Pluginsquartz.plugin.xml.fileNames = ~/quartz_jobs.xml# export this server to remoting contextquartz.scheduler.exporter.type = Quartz.Simpl.RemotingSchedulerExporter, Quartzquartz.scheduler.exporter.port = 555quartz.scheduler.exporter.bindName = QuartzSchedulerquartz.scheduler.exporter.channelType = tcpquartz.scheduler.exporter.channelName = httpQuartzquartz.scheduler.exporter.rejectRemoteRequests = true
quartz_jobs.xml
true
cancelOrderJob
ABC.OMS.Order
取消订单计划任务
QuartzTest.Jobs.CancelOrderJob,QuartzTest.Jobs
true
false
cancelOrderTrigger
ABC.OMS.Order
cancelOrderJob
ABC.OMS.Order
2015-01-22T00:00:00+08:00
0/2 * * * * ?

 

class Program    {        static void Main(string[] args)        {            // var properties = new NameValueCollection();            // properties["quartz.scheduler.instanceName"] = "RemoteServer";            // properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";            // properties["quartz.threadPool.threadCount"] = "5";            // properties["quartz.threadPool.threadPriority"] = "Normal";            // properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz";            // properties["quartz.scheduler.exporter.port"] = "555";            // properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler";            // properties["quartz.scheduler.exporter.channelType"] = "tcp";            // properties["quartz.scheduler.exporter.channelName"] = "httpQuartz";            // properties["quartz.scheduler.exporter.rejectRemoteRequests"] = "true";            //ISchedulerFactory schedFact = new StdSchedulerFactory(properties);            ISchedulerFactory schedFact = new StdSchedulerFactory();            IScheduler sched = schedFact.GetScheduler().Result;            sched.Start();            IJobDetail cancelOrderJob = JobBuilder.Create
() .WithIdentity("cancelOrderJob", "ABC.OMS.Order") .Build(); ITrigger cancelOrderTrigger = TriggerBuilder.Create() .WithIdentity("cancelOrderTrigger", "ABC.OMS.Order") .StartNow() .WithSimpleSchedule(x => x .WithIntervalInSeconds(3) .RepeatForever()) .Build(); IJobDetail job1 = JobBuilder.Create
() .WithIdentity("PaymentConfirmedJod", "group1") .Build(); ITrigger trigger1 = TriggerBuilder.Create() .WithIdentity("PaymentConfirmedTrigger", "group1") .StartNow() .WithSimpleSchedule(x => x .WithIntervalInSeconds(2) .RepeatForever()) .Build(); sched.ScheduleJob(cancelOrderJob, cancelOrderTrigger); sched.ScheduleJob(job1, trigger1); System.Console.ReadKey(); } }

 

namespace QuartzTest.Jobs{    [DisallowConcurrentExecution]  //设置JOB不允许并行执行    public class CancelOrderJob : IJob    {        System.Threading.Tasks.Task IJob.Execute(IJobExecutionContext context)        {            System.Console.WriteLine(string.Format("[{0}]订单已取消", DateTime.Now));            Thread.Sleep(5000);            return System.Threading.Tasks.Task.CompletedTask;        }    }}

 

转载于:https://www.cnblogs.com/huangzelin/p/9706690.html

你可能感兴趣的文章
我的友情链接
查看>>
迟来的2017总结文
查看>>
java 散列算法计算重复数据
查看>>
我的友情链接
查看>>
TCP/UDP Socket编程步骤
查看>>
RabbitMQ与PHP
查看>>
内存对齐模式与结构体
查看>>
最大子数组和
查看>>
fir.im Weekly - 聊聊让人向往的远程开发工作
查看>>
give root password for maintenance错误解决办法!
查看>>
web 应用的常见 漏洞有哪些
查看>>
linux sort
查看>>
Find命令使用详解
查看>>
CentOS7安装mysql5.7.16后,第一次登陆的默认密码
查看>>
学习之linux下cal,ls
查看>>
nfs
查看>>
Psexec 远程执行文件 提示 拒绝访问
查看>>
我的友情链接
查看>>
ibdata1是什么?
查看>>
IT十八掌作业_java基础第十三天_IO
查看>>