Method 1: directly write data into the code
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();
Method 2: Write to app. config or web. config
<quartz> <add key="quartz.scheduler.instanceName" value="ConsoleScheduler"/> <add key="quartz.scheduler.instanceId" value="instance_one"/> <add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz"/> <add key="quartz.threadPool.threadCount" value="10"/> <add key="quartz.threadPool.threadPriority" value="Normal"/> <add key="quartz.jobStore.misfireThreshold" value="60000"/> <add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz"/> <add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz"/> <add key="quartz.jobStore.useProperties" value="true"/> <add key="quartz.jobStore.dataSource" value="default"/> <add key="quartz.jobStore.tablePrefix" value="QRTZ_"/> <add key="quartz.dataSource.default.connectionString" value="Server=xx;Database=xx;User Id=xx;Password=xx"/> <add key="quartz.dataSource.default.provider" value="SqlServer-20"/> </quartz>
Method 3: write data to the quartz. config file
# You can configure your scheduler in either <quartz> configuration 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
Method 2 and 3 are called as follows:
ISchedulerFactory sf = new StdSchedulerFactory();IScheduler sched = sf.GetScheduler();
Why is the first method possible? We can find the following Debug source code:
public StdSchedulerFactory(NameValueCollection props){ Initialize(props);}public virtual void Initialize(NameValueCollection props){ cfg = new PropertiesParser(props); ValidateConfiguration();}
The reasons for the latter two methods are as follows:
Public virtual IScheduler GetScheduler () {if (cfg = null) {Initialize ();} SchedulerRepository schedRep = SchedulerRepository. instance; isched1_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! = Null & requestedFile. Trim (). Length> 0? RequestedFile :"~ /Quartz. config "; // check for specials try {propFileName = FileUtil. ResolveFile (propFileName);} unfinished
Note the code NameValueCollection props = (NameValueCollection) ConfigurationManager. GetSection ("quartz"); (search for app. config or web. config)
And string requestedFile = QuartzEnvironment. GetEnvironmentVariable (PropertiesFile); (find quartz. config)
String propFileName = requestedFile! = Null & requestedFile. Trim (). Length> 0? RequestedFile :"~ /Quartz. config ";