Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure jobs and triggers

2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to configure jobs and triggers". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's take you to learn "how to configure jobs and triggers"!

Quartz-related configurations have three quartz.config, quartz_jobs.xml, log4net.config. where quartz.config is the basic configuration, quartz_jobs.xml is the relevant job configuration file, and log4net.config is the logging configuration.

I. Quartz configuration

Quartz.config , is Quartz. NET is the basic configuration, mainly the configuration of quartz_jobs.xml path, and other related parameters. The default quartz task configuration file is quartz_jobs.xml, which can be set in the root directory of quartz service by quartz.plugin.xml.fileNames = ~/quartz_jobs.xml.

# You can configure your scheduler in either configuration section# or in quartz properties file# Configuration section has precedencequartz.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

II. Task configuration

quartz_jobs.xml, which is the relevant job task configuration file. There are two main nodes, job and trigger.

true Job1 JobGroup Quartz Job1 Quartz.Net.Jobs.Job1,Quartz.Net.Jobs true false Job2 JobGroup Quartz Job2 Quartz.Net.Jobs.Job2,Quartz.Net.Jobs true false Job1Trigger JobTriggerGroup Job1 JobGroup 0/30 * * * * ? Job2Trigger1 JobTriggerGroup Job2 JobGroup 0 * * * * ?

Job task. This node is used to define each specific task. For multiple tasks, please create multiple job nodes.

1. name Task name. The names of multiple jobs in the same group cannot be the same, for example:Job1

2. group task group, used to identify the task group, such as:JobGroup

3. The specific type of job-type task and the assembly it belongs to. The class name including the complete namespace that implements the IJob interface, and the assembly name, such as Quartz.Net.Jobs.Job1,Quartz.Net.Jobs

The rest of the nodes can be set by default.

Trigger task trigger, mainly defines when and how to trigger a job. Multiple triggers can be defined for the same job, and each trigger has its own independent execution schedule. Each trigger must define a trigger type (calendar-interval, simple, cron).

calendar-interval is rarely used, usually simple and cron, which is not explained here.

simple Trigger for simple tasks that can schedule tasks for repeated execution

1. name Trigger name, names in the same group must be different

2. group Trigger group

3. job-name The name of the task to be dispatched. The job-name must be exactly the same as the name in the corresponding job node, such as: Job1

4. job-group The group to which the scheduling task (job) belongs. This value must be exactly the same as the group in the job, e.g. JobGroup

5. repeat-count task execution times, such as:-1 means infinite execution times, 10 means 10 execution times

6. repeat-interval Task trigger interval, unit: ms, for example:10000 Executed once every 10 seconds

cron complex task triggers, mainly using cron expressions to customize task scheduling, generally used more are cron triggers.

1. name Trigger name, names in the same group must be different

2. group Trigger group

3. description Trigger description

4. job-name The name of the task to be dispatched. Note that the job-name must be exactly the same as the name in the corresponding job node, such as: Job1

5. job-group The group to which the scheduling task (job) belongs. This value must be exactly the same as the group in the job, e.g. JobGroup

6. cron-expression The cron expression executed by the task, such as:0/30 * ** * ? Every 30 seconds.

The rest of the nodes can be set by default.

Flexible configuration of quartz_jobs.xml according to actual project needs, without additional modification of other background code, to achieve flexible multitask scheduling, it should be noted that after modifying the quartz_jobs.xml file, the quartz service will not reload the file by default, you need to restart the service.

At this point, I believe everyone has a deeper understanding of "how to configure jobs and triggers," so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 263

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report