quartz.net 2.0作业不执行并行

时间:2016-10-05 11:25:35

标签: quartz.net quartz.net-2.0

我们通过xml文件配置了3个quartz.net(版本2.3.3)作业

IInterruptableJob Job1Class用DisallowConcurrentExecution标记,并被Job1&在xml文件中的Job2(当然具有不同的作业数据)。

IInterruptableJob Job3Class由Job3在xml文件中使用。

quartz.threadPool.threadCount通过配置文件设置为6。

在3个作业中,2个作业长时间运行,我们要求所有3个作业应该并行执行,但很多时候我们发现它不执行并行。那么为什么它不能并行执行。

以下是示例xml文件。

<?xml version="1.0" encoding="utf-8" ?>
<job-scheduling-data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://quartznet.sourceforge.net/JobSchedulingData" version="2.0">
  <schedule>
    <job>
      <name>Job1</name>
      <group>JobGroup</group>
      <job-type>Some.Job1.Class, Some.Job1.Class.Assembly</job-type>
      <durable>false</durable>
      <recover>false</recover>
      <job-data-map>
        <entry><key>keys</key><value>values</value></entry>
      </job-data-map>
    </job>
    <trigger>
      <simple>
        <name>Job1Trigger1</name>
        <group>Triggers</group>
        <job-name>Job1</job-name>
        <job-group>JobGroup</job-group>
        <start-time-seconds-in-future>1</start-time-seconds-in-future>
        <repeat-count>0</repeat-count>
        <repeat-interval>1</repeat-interval>
      </simple>
    </trigger>
    <trigger>
      <cron>
        <name>Job1Trigger2</name>
        <group>Triggers</group>
        <job-name>Job1</job-name>
        <job-group>JobGroup</job-group>
        <cron-expression>0 0/1 * * * ?</cron-expression>
      </cron>
    </trigger>
    <job>
      <name>Job2</name>
      <group>JobGroup</group>
      <job-type>Some.Job1.Class, Some.Job1.Class.Assembly</job-type>
      <durable>false</durable>
      <recover>false</recover>
      <job-data-map>
        <entry><key>keys</key><value>values</value></entry>
      </job-data-map>
    </job>
    <trigger>
      <simple>
        <name>Job2Trigger1</name>
        <group>Triggers</group>
        <job-name>Job2</job-name>
        <job-group>JobGroup</job-group>
        <start-time-seconds-in-future>1</start-time-seconds-in-future>
        <repeat-count>1</repeat-count>
        <repeat-interval>1</repeat-interval>
      </simple>
    </trigger>
    <trigger>
      <cron>
        <name>Job2Trigger2</name>
        <group>Triggers</group>
        <job-name>Job2</job-name>
        <job-group>JobGroup</job-group>
        <cron-expression>0 0 2 1/1 * ? *</cron-expression>
      </cron>
    </trigger>
    <job>
      <name>Job3</name>
      <group>JobGroup</group>
      <job-type>Some.Job3.Class, Some.Job3.Class.Assembly</job-type>
      <durable>false</durable>
      <recover>false</recover>
      <job-data-map>
        <entry><key>keys</key><value>values</value></entry>
      </job-data-map>
    </job>
    <trigger>
      <simple>
        <name>Job3Trigger1</name>
        <group>Triggers</group>
        <job-name>Job3</job-name>
        <job-group>JobGroup</job-group>
        <start-time-seconds-in-future>1</start-time-seconds-in-future>
        <repeat-count>1</repeat-count>
        <repeat-interval>1</repeat-interval>
      </simple>
    </trigger>
    <trigger>
      <cron>
        <name>Job3Trigger2</name>
        <group>Triggers</group>
        <job-name>Job3</job-name>
        <job-group>JobGroup</job-group>
        <cron-expression>0/30 * * * * ?</cron-expression>
      </cron>
    </trigger>
  </schedule>
</job-scheduling-data>

1 个答案:

答案 0 :(得分:0)

Job1Job2无法并行运行,因为您告诉Quartz Job1Class具有DisallowConcurrentExecution属性。此属性适用于类,而不适用于对象。 Quartz不会运行多个Job1Class实例。要解决此问题,请从Job1Class中删除DisallowConcurrentExecution属性,并从Job1Class创建2个子类。一个用于Job1,一个用于Job2。然后给每个新类赋予属性,它应该像你想要的那样工作。