quartz.config# You can configure your scheduler in eitherconfiguration 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.xmltrue 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; } }}