【问题标题】:How many schedulers can I create per application?每个应用程序可以创建多少个调度程序?
【发布时间】:2016-09-02 20:37:00
【问题描述】:

似乎StdSchedulerFactory 返回了一个名称在配置中定义的单例:

<add key="quartz.scheduler.instanceName" value="MyQuartzScheduler" />

由于石英配置部分由键值对组成,看起来使用工厂实例化调度程序将可用调度程序的数量限制为一个。

【问题讨论】:

    标签: quartz.net


    【解决方案1】:

    AFIAK,您可以在任何应用程序中创建任意数量的调度程序,但您不能为此使用默认的quartz 配置方法,因为它只需要一个调度程序属性集合(查看StdSchedulerFactoryimplementation 和@987654322 @博客如果有趣):

    默认情况下,在 Quartz.Net 中,StdSchedulerFactory 负责配置调度器。当 Quartz.Net 调度器启动时,工厂会尝试通过在不同的地方寻找配置信息来自动配置一个调度器:

    • 托管应用程序的配置文件
    • 在环境变量中指定的文件
    • quartz.config 文件
    • 嵌入式配置文件

    所以您可以做的不是使用自动调度程序配置,而是
    自己创建一个单独的属性集合并将它们传递给调度程序创建构造函数:

    public StdSchedulerFactory(NameValueCollection props);
    
    • 使用代码方法:

      NameValueCollection scheduler1Properties = new NameValueCollection();     
      properties["quartz.scheduler.instanceName"] = "SingleThreadScheduler"; 
      properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
      properties["quartz.threadPool.threadCount"] = "1";
      ...
      var factory = new StdSchedulerFactory(scheduler1Properties);
      
    • 或者您可以创建单独的石英配置并直接使用石英PropertiesParser 类来读取

      /// <summary>
      /// Reads the properties from file system.
      /// </summary>
      /// <param name="fileName">The file name to read resources from.</param>
      /// <returns></returns>
      public static PropertiesParser ReadFromFileResource(string fileName)
      

      并获取收藏:

      /// <summary>
      /// Gets the underlying properties.
      /// </summary>
      /// <value>The underlying properties.</value>
      public virtual NameValueCollection UnderlyingProperties
      {
          get { return props; }
      }
      

      //PropertiesParser类直接用于default配置读取实现。

    【讨论】:

      猜你喜欢
      • 2011-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-17
      • 1970-01-01
      • 2020-09-17
      • 2012-12-27
      • 1970-01-01
      相关资源
      最近更新 更多