博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Quartz.Net 学习随手记之03 配置文件
阅读量:5888 次
发布时间:2019-06-19

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

第一种方式:直接写入代码中

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 either 
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

第二和第三中方式调用方式如下

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

你可能感兴趣的文章
mysql 字符串字段中查找非ascii字符
查看>>
日常开发常用网站(持续更新……)
查看>>
7-8 哈利·波特的考试(25 分)(图的最短路径Floyd算法)
查看>>
《高老头》
查看>>
Javascript 弹出窗口总结(收集)
查看>>
ERP实施顾问,请找准自己的定位
查看>>
Android studio 3.1.2报错,no target device found
查看>>
Tarjan 割边(桥)
查看>>
Dubbo服务,后台管理,监控中心搭建的简单实践
查看>>
poj 1321 棋盘问题
查看>>
Python基本图形绘制
查看>>
捷径 - The certain shortcut
查看>>
windows与windows之间传输文件
查看>>
拓展+属性
查看>>
struts2 常量
查看>>
端口的作用
查看>>
VS XCOPY
查看>>
完整的删除
查看>>
红帽(Red Hat Linux)下SVN服务器的安装与配置
查看>>
RecyclerView使用介绍
查看>>