zoukankan      html  css  js  c++  java
  • 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";

    作者:舍长
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
  • 相关阅读:
    2019年----沉淀的一年
    条目八《永不建立auto_ptr的容器》
    条目七《如果容器中包含了通过new操作创建的指针,切记在容器对象析构前将指针delete掉》
    条目六《当心C++编译器中最烦人的分析机制》
    条目五《尽量使用区间成员函数代替它们的单元素兄弟》
    cpu上下文切换
    条目四《用empty来代替检查size()是否为0》
    条目三《确保容器中的副本对象高效而正确》
    ORB与LBP、HOG
    C++
  • 原文地址:https://www.cnblogs.com/panchunting/p/3016899.html
Copyright © 2011-2022 走看看