第一种方式:直接写入代码中
NameValueCollection properties = new NameValueCollection(); properties["quartz.scheduler.instanceName"] = "ConsoleScheduler"; properties["quartz.scheduler.instanceId"] = "instance_one"; properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz"; properties["quartz.threadPool.threadCount"] = "10"; properties["quartz.threadPool.threadPriority"] = "Normal"; properties["quartz.jobStore.misfireThreshold"] = "60000"; properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz"; properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz"; properties["quartz.jobStore.useProperties"] = "true"; properties["quartz.jobStore.dataSource"] = "default"; properties["quartz.jobStore.tablePrefix"] = "QRTZ_"; properties["quartz.dataSource.default.connectionString"] = "Server=xx;Database=xx;User Id=xx;Password=xx"; properties["quartz.dataSource.default.provider"] = "SqlServer-20"; ISchedulerFactory sf = new StdSchedulerFactory(properties); IScheduler sched = sf.GetScheduler();
第二种方式:写入app.config或web.config中
第三种方式:写入quartz.config文件中
# You can configure your scheduler in eitherconfiguration section # or in quartz properties file # Configuration section has precedence quartz.scheduler.instanceName = ServerScheduler # configure thread pool info quartz.threadPool.type = Quartz.Simpl.SimpleThreadPool, Quartz quartz.threadPool.threadCount = 10 quartz.threadPool.threadPriority = Normal # job initialization plugin handles our xml reading, without it defaults are used quartz.plugin.xml.type = Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz quartz.plugin.xml.fileNames = ~/quartz_jobs.xml # export this server to remoting context quartz.scheduler.exporter.type = Quartz.Simpl.RemotingSchedulerExporter, Quartz quartz.scheduler.exporter.port = 555 quartz.scheduler.exporter.bindName = QuartzScheduler quartz.scheduler.exporter.channelType = tcp quartz.scheduler.exporter.channelName = httpQuartz # job store quartz.jobStore.misfireThreshold =60000 quartz.jobStore.type = Quartz.Impl.AdoJobStore.JobStoreTX, Quartz quartz.jobStore.driverDelegateType = Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz quartz.jobStore.useProperties = true quartz.jobStore.dataSource = default quartz.jobStore.tablePrefix = QRTZ_ quartz.dataSource.default.connectionString = Server=xx;Database=xx;User Id=xx;Password=xx quartz.dataSource.default.provider = SqlServer-20
第二和第三中方式调用方式如下
ISchedulerFactory sf = new StdSchedulerFactory();IScheduler sched = sf.GetScheduler();
为什么第一种方式可以,我们Debug源码可以发现如下
public StdSchedulerFactory(NameValueCollection props){ Initialize(props);}public virtual void Initialize(NameValueCollection props){ cfg = new PropertiesParser(props); ValidateConfiguration();}
后两者方式原因如下
public virtual IScheduler GetScheduler(){ if (cfg == null) { Initialize(); } SchedulerRepository schedRep = SchedulerRepository.Instance; IScheduler sched = schedRep.Lookup(SchedulerName); if (sched != null) { if (sched.IsShutdown) { schedRep.Remove(SchedulerName); } else { return sched; } } sched = Instantiate(); return sched;}public void Initialize(){ // short-circuit if already initialized if (cfg != null) { return; } if (initException != null) { throw initException; } NameValueCollection props = (NameValueCollection) ConfigurationManager.GetSection("quartz"); string requestedFile = QuartzEnvironment.GetEnvironmentVariable(PropertiesFile); string propFileName = requestedFile != null && requestedFile.Trim().Length > 0 ? requestedFile : "~/quartz.config"; // check for specials try { propFileName = FileUtil.ResolveFile(propFileName); }未完
注意代码NameValueCollection props = (NameValueCollection) ConfigurationManager.GetSection("quartz"); (寻找app.config或web.config)
和string requestedFile = QuartzEnvironment.GetEnvironmentVariable(PropertiesFile);(寻找quartz.config)
string propFileName = requestedFile != null && requestedFile.Trim().Length > 0 ? requestedFile : "~/quartz.config";
http://www.cnblogs.com/panchunting/archive/2013/04/12/3016899.html