【quartz】 入门-配置文件

quartz 启动

 NameValueCollection props = (NameValueCollection)ConfigurationManager.GetSection("quartz");

            //PropertiesParser cfg = new PropertiesParser(props);

            ISchedulerFactory sf = new StdSchedulerFactory(props);

            IScheduler sched = sf.GetScheduler();

            sched.Start();

app.config 或者 web.config

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <configSections>

    <section name="quartz" type="System.Configuration.NameValueSectionHandler" />

  </configSections>



  <quartz>

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

    <add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz"/>

    <add key="quartz.threadPool.threadCount" value="10"/>

    <add key="quartz.threadPool.threadPriority" value="2"/>

    <add key="quartz.jobStore.misfireThreshold" value="60000"/>

    <add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz"/>

    <!--******************************Plugin配置********************************************* -->

    <add key="quartz.plugin.xml.type" value="Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz" />

    <add key="quartz.plugin.xml.fileNames" value="~/quartz_jobs.xml"/>

  </quartz>

</configuration>

 

~/quartz_jobs.xml

simple和cron两种方式
<?xml version="1.0" encoding="UTF-8"?>



<!-- This file contains job definitions in schema version 2.0 format -->



<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>sampleJob</name>

      <group>sampleGroup</group>

      <description>Sample job for Quartz Server</description>

      <job-type>quartzdemo.HelloJob, quartzdemo</job-type>

      <durable>true</durable>

      <recover>false</recover>

    </job>

    <trigger>

      <simple>

        <name>sampleSimpleTrigger</name>

        <group>sampleSimpleGroup</group>

        <description>Simple trigger to simply fire sample job</description>

        <job-name>sampleJob</job-name>

        <job-group>sampleGroup</job-group>

        <misfire-instruction>SmartPolicy</misfire-instruction>

        <repeat-count>-1</repeat-count>

        <repeat-interval>10000</repeat-interval>

      </simple>

    </trigger>





    <job>

      <name>sampleJob2</name>

      <group>sampleGroup</group>

      <description>Sample job for Quartz Server</description>

      <job-type>quartzdemo.HelloJob2, quartzdemo</job-type>

      <durable>true</durable>

      <recover>false</recover>

    </job>

    <trigger>

      <cron>

        <name>sampleSimpleTrigger2</name>

        <group>sampleSimpleGroup2</group>

        <description>Simple trigger to simply fire sample job</description>

        <job-name>sampleJob2</job-name>

        <job-group>sampleGroup</job-group>

        <cron-expression>0/3 * * * * ?</cron-expression>

      </cron>

    </trigger> 

  </schedule>
</job-scheduling-data>

 

你可能感兴趣的:(quartz)