Quartz.Net 学习随手记之03 配置文件
第一种方式:直接写入代码中

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

第三种方式:写入quartz.config文件中

# 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

第二和第三中方式调用方式如下
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
Quartz.Net 学习随手记之03 配置文件的更多相关文章
- Quartz定时任务学习(二)web应用/Quartz定时任务学习(三)属性文件和jar
web中使用Quartz 1.首先在web.xml文件中加入 如下内容(根据自己情况设定) 在web.xml中添加QuartzInitializerServlet,Quartz为能够在web应用中使用 ...
- Quartz定时任务学习(二)web应用
web中使用Quartz 1.首先在web.xml文件中加入 如下内容(根据自己情况设定) 在web.xml中添加QuartzInitializerServlet,Quartz为能够在web应用中使用 ...
- [小北De编程手记] : Lesson 03 - Selenium For C# 之 元素定位
无论哪一种自动化测试的驱动框架(基于B/S,桌面应用,还是手机App).都应当具有一套优秀的元素定位技术.通常的自动化测试流程也可以简单的归结为是一个从被测试程序中识别或是定位元素以及执行操作和验证元 ...
- MyBatis学习 之 四、MyBatis配置文件
目录(?)[-] 四MyBatis主配置文件 properties属性 settings设置 typeAliases类型别名 typeHandlers类型句柄 ObjectFactory对象工厂 pl ...
- 【转】MyBatis学习总结(三)——优化MyBatis配置文件中的配置
[转]MyBatis学习总结(三)——优化MyBatis配置文件中的配置 一.连接数据库的配置单独放在一个properties文件中 之前,我们是直接将数据库的连接配置信息写在了MyBatis的con ...
- Quartz.NET学习系列
Quartz.NET它是一个开源的任务调度引擎,对于周期性任务,持久性任务提供了很好的支持,并且支持持久性.集群等功能. 这是什么对我来说Quartz.NET学习记录: 源代码下载http://yun ...
- Quartz框架学习(1)—核心层次结构
Quartz框架学习 Quartz(任务调度)框架的核心组件: job:任务.即任务调度行为中所要调度的对象. trigger:触发器.是什么促使了一个任务的调度?当然是时间.这也算事件驱动类型程序. ...
- Solr 6.7学习笔记(02)-- 配置文件 managed-schema (schema.xml) -- 样例(6)
managed-schema 样例: <?xml version="1.0" encoding="UTF-8" ?> <!-- License ...
- Solr 6.7学习笔记(02)-- 配置文件 managed-schema (schema.xml)(3)
5. <fieldType> fieldType主要定义了一些字段类型,其name属性值用于前面<field>中的type属性的值.e.g. <fieldTyp ...
随机推荐
- The New Stack:KubeEdge将Kubernetes的能力延伸至边缘
3月29日,权威技术分析网站The New Stack在Edge/IoT专栏发表了关于边缘计算项目KubeEdge的最新调研报告.原文观点如下: https://github.com/kubeedge ...
- JVM系列二:垃圾回收
什么时候回收对象 引用计数法 1.原理:为对象添加一个引用计数器,当对象增加一个引用时计数器加 1,引用失效时计数器减 1.引用计数为 0 的对象可被回收. 2.缺点:无法解决循环引用问题 可达性分析 ...
- 算法102----360笔试(m进制不进位相加最大值)
转自:https://blog.csdn.net/qq_18310041/article/details/99656445 import copy # m进制 m = 5 n = 5 line = [ ...
- vue 全局变量的处理方式
vue项目中配置全局动态变量的方式:sessionStorage,vuex多个组件都会用到的公共的状态和方法(复用):vue 全局混入vue项目中配置全局静态变量的方式:vue 的原型链: globa ...
- AOP(execution表达式)
作者:门罗的魔术师 推荐:y-yg 在使用spring框架配置AOP的时候,不管是通过XML配置文件还是注解的方式都需要定义pointcut"切入点" 例如定义切入点表达式 ex ...
- 后端token认证模板
1.创建一个视图 from rest_framework import exceptions from app01 import models from rest_framework.authenti ...
- Linux(centos 7) 安装nginx
在安装nginx之前需要安装依赖的包 一. gcc 安装安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装: yum install gcc- ...
- mysql kill所有Sleep/Execute进程
现查出需要kill的进程: SELECT GROUP_CONCAT(CONCAT('kill ',id) SEPARATOR '; ') AS cmd FROM information_schema. ...
- LOJ P10171 牧场的安排 题解
每日一题 day6 打卡 Analysis 状压dp dp[i][j]+=dp[i-1][k]; #include<iostream> #include<cstdio> #in ...
- 十二.虚拟Web主机
*********************** 修改apache默认的网页文件存放位置 ]# mkdir /var/www/myweb ]# echo "I am MyWeb" & ...