Quartz. NET Summary (3) Quartz configuration, quartz. netquartz

Source: Internet
Author: User

Quartz. NET Summary (3) Quartz configuration, quartz. netquartz

The first two articles have introduced Quartz. NET and Cron expression. Today we will talk about the Quartz configuration. The Quartz-related configuration has three quartz. config, quartz_jobs.xml, and log4net. config. Here, quartz. config is the basic configuration, quartz_jobs.xml is the relevant job task configuration file, and log4net. config is the configuration of log records.

 

1.Quartz. config,Z. NET is a basic configuration, mainly used to configure the quartz_jobs.xml path and other related parameters. The default quartz job configuration file is quartz_jobs.xml. Under the root directory of the quartz service, you can use quartz. plugin. xml. fileNames = ~ in quartz. config ~ /Quartz_jobs.xml.

# 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 infoquartz.threadPool.type = Quartz.Simpl.SimpleThreadPool, Quartzquartz.threadPool.threadCount = 10quartz.threadPool.threadPriority = Normal # job initialization plugin handles our xml reading, without it defaults are usedquartz.plugin.xml.type = Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartzquartz.plugin.xml.fileNames = ~/quartz_jobs.xml # export this server to remoting contextquartz.scheduler.exporter.type = Quartz.Simpl.RemotingSchedulerExporter, Quartzquartz.scheduler.exporter.port = 555quartz.scheduler.exporter.bindName = QuartzSchedulerquartz.scheduler.exporter.channelType = tcpquartz.scheduler.exporter.channelName = httpQuartz

 

2.Quartz_jobs.xml,Is the relevant job configuration file. There are two groups of nodes: job and trigger.

<? 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> <! -- Define Job1 --> <job> <name> Job1 </name> <group> JobGroup </group> <description> Quartz Job1 </description> <job-type> Quartz. net. jobs. job1, Quartz. net. jobs </job-type> <durable> true </durable> <recover> false </recover> </job> <! -- Define Job2 --> <job> <name> Job2 </name> <group> JobGroup </group> <description> Quartz Job2 </description> <job-type> Quartz. net. jobs. job2, Quartz. net. jobs </job-type> <durable> true </durable> <recover> false </recover> </job> <! -- Define a Job1 trigger to execute a Job1 task every 30 seconds --> <trigger> <cron> <name> Job1Trigger </name> <group> JobTriggerGroup </group> <job-name> job1 </job-name> <job-group> JobGroup </job-group> <cron-expression> 0/30 ****? </Cron-expression> </cron> </trigger> <! -- Define a Job2 trigger to execute a Job2 task every minute --> <trigger> <cron> <name> Job2Trigger1 </name> <group> JobTriggerGroup </group> <job-name> Job2 </job-name> <job-group> JobGroup </job-group> <cron-expression> 0 ****? </Cron-expression> </cron> </trigger> </schedule> </job-scheduling-data>

JobTask,This node is used to define each specific task. You can create multiple job nodes for multiple tasks.

 

1. name the task name. The names of multiple jobs in the same group cannot be the same, for example, <name> Job1 </name>

2. group the group to which the task belongs, for example, <group> JobGroup </group>

3. the specific type and assembly of the job-type task, which implements the class name and Assembly name of the IJob interface containing the complete namespace, such as <job-type> Quartz. net. jobs. job1, Quartz. net. jobs </job-type>

 

The remaining nodes can be set by default.

 

TriggerTask trigger,It mainly defines the time and method for triggering a job. The same job can define multiple triggers and each trigger can execute and schedule independently, each trigger must define a trigger type (calendar-interval, simple, cron ).

Calendar-interval is rarely used. It is generally simple and cron, which is not described here.

 

A trigger for a simple task, which can be scheduled for repeated tasks.

1. name trigger name, which must be different in the same group

2. group trigger group

3. job-name: name of the task to be scheduled. The job-name must be exactly the same as the name in the corresponding job node, for example, <job-name> Job1 </job-name>

4. The group to which the job (job) belongs. The value must be identical to the group in the job, for example, <job-group> JobGroup </job-group>

5. the number of repeat-count tasks, for example, <repeat-count>-1 </repeat-count> indicates unlimited execution, <repeat-count> 10 </repeat-count> indicates 10 executions.

6. Trigger interval of the repeat-interval task, in milliseconds. For example, <repeat-interval> 10000 </repeat-interval> is executed every 10 seconds.

 

Cron complex task triggers mainly use cron expressions to customize task scheduling. Generally, cron triggers are used. For more information about cron expressions, see the previous blog Quartz. NET Summary (2) CronTrigger and Cron expressions.

1. name trigger name, which must be different in the same group

2. group trigger group

3. description trigger description

4. The name of the job to be scheduled. Note that the job-name must be exactly the same as the name in the corresponding job node, for example, <job-name> Job1 </job-name>

5. The group to which the job (job) belongs. The value must be identical to the group in the job, for example, <job-group> JobGroup </job-group>

6. cron-expression indicates the cron expression executed by the cron-expression task, for example, <cron-expression> 0/30 ****? </Cron-expression> run once every 30 seconds

 

The remaining nodes can be set by default.

You can flexibly configure quartz_jobs.xml according to your project requirements. You do not need to modify other background code to implement flexible multi-task scheduling. Note that after you modify the quartz_jobs.xml file, the quartz service does not reload the file by default. You need to restart the service.

 

3. log4net. config

For more information, see log4net configuration.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.