首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否要在前一个实例完成后才运行quartz.net定期计划任务?

是否要在前一个实例完成后才运行quartz.net定期计划任务?
EN

Stack Overflow用户
提问于 2013-02-16 00:56:49
回答 1查看 2K关注 0票数 0

我刚刚开始使用Quartz.net。通过在我的app.config中添加以下内容,我能够让它运行起来

代码语言:javascript
复制
<configSections>
    <section name="quartz"
     type="System.Configuration.NameValueSectionHandler, 
         System, Version=1.0.5000.0,Culture=neutral, 
         PublicKeyToken=b77a5c561934e089" />
</configSections>
代码语言:javascript
复制
<!-- Configure Thread Pool -->
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
<add key="quartz.threadPool.threadCount" value="10" />
<add key="quartz.threadPool.threadPriority" value="Normal" />

<!-- Check for updates to the scheduling every 10 seconds -->
<add key="quartz.plugin.xml.scanInterval" value="10" />

<!-- Configure Job Store -->
<add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz" />
<add key="quartz.plugin.xml.type" value="Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz"/>
<add key="quartz.plugin.xml.fileNames" value="quartz.config" />

我添加了以下Quartz.config:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                version="2.0">
  <processing-directives>
    <overwrite-existing-data>true</overwrite-existing-data>
  </processing-directives>

  <schedule>
    <job>
      <name>ResultProcessor</name>
      <group>Result</group>
      <description>Normalizes results.</description>
      <job-type>TestingNamespace.TestingJob,xxx</job-type>
    </job>

    <trigger>
      <simple>
        <name>ResultProcessorTrigger</name>
        <group>Result</group>
        <description>Trigger for result processor</description>
        <job-name>ResultProcessor</job-name>
        <job-group>Result</job-group>
        <misfire-instruction>SmartPolicy</misfire-instruction>
        <repeat-count>-1</repeat-count>
        <repeat-interval>60000</repeat-interval> <!-- Every 60 seconds -->
      </simple>
    </trigger>
  </schedule>
</job-scheduling-data>

下面的类正在执行:

代码语言:javascript
复制
namespace TestingNamespace
{
    class TestingJob: IJob
    {
        protected static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public void Execute(IJobExecutionContext context)
        {
            try
            {
                logger.Info("Executing PROCESSING");
                Thread.Sleep(TimeSpan.FromMinutes(5));
            }
            catch (Exception ex)
            {
                logger.Error("Problem running Execute.", ex);
                throw;
            } // End of catch
        } // End of Run
    } // End of TestingJob
} // End of namespace

正如您在作业中看到的,我有一个Thread.Sleep(TimeSpan.FromMinutes(5));让作业休眠5分钟。问题是,我不希望流程的多个实例同时运行。在当前的设置中,我仍然每隔60秒收到一条Executing PROCESSING消息。

有没有办法使用Quartz.net让这个作业只在它的前一个实例完成后运行?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-16 05:13:17

这是您应该使用DisallowConcurrentExecution属性标记作业的地方。这背后的推理/行为在这里解释了Quartz.net scheduler and IStatefulJob (IStatefulJob标记接口是2.0之前的方式)。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14899548

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档