Quartz. NET architecture and source code analysis series Part 1: quartz. Net Introduction

Source: Internet
Author: User
Overview

The goal of Job Scheduling is to ensure efficient data processing processes based on predefined time and specified sequence, so as to maximize the use of system resources. Batch Processing is an operation that runs in sequence in the background without end user intervention.

Windows XP also comes with a "Task Plan", which is a simple task scheduling application, you can find it in "start"> "All Programs"> "accessories"> "System Tools"> "Task Plan. 1;

Figure 1. Windows Task Plan

Quartz. NET is an open-source job scheduling framework that can be used in small applications or even enterprise applications. It has the following features:

  • API operations are simple. With just a few lines of simple code, you can schedule your jobs in the application and monitor job execution in real time.
  • The trigger function is powerful and provides a finer trigger granularity than the Windows task plan. You can use the "cron expression (which will be introduced later)" to implement it, for example, am from Monday to Friday, PM (Working Hours) to execute a task
  • Good scalability. It is based on Interface Programming. You can implement your own schedule scheduler, job, trigger, etc.
  • Jobs can be stored in Ram or persisted to databases. Multiple database types are supported: sqlserver, Oracle, MySQL, etc.
  • Cluster, an advanced application that allows you to create load balancing and fault tolerance between multiple computers.
Use

The latest version is the official version 1.0, which includes quartz.2008.sln and quartz. server.2008.sln (step-by-step application, which will be analyzed in the following series). Use Visual Studio 2008 to open quartz.2008.sln, as shown in solution 2:

Figure 2. Quartz. Net Solution

Quartz. NET is the core quartz library. Its file structure and function 3 are shown in the following figure:

Figure 3. Quartz. Net file structure

The file organization structure of quartz. Net does not follow certain specifications. For example, the "SPI" folder stores the scheduler, job, and thread pool interfaces. Many interfaces are also placed on the outermost layer, as shown in 3. But most of them can be identified directly, so this will not have a great impact on our reading code.

The following is a simple example of quartz. Net:

Code
// Initialize the scheduler Factory
Ischedulerfactory Sf = new stdschedulerfactory ();
// Obtain the default Scheduler
Ischeduler scheduler = SF. getscheduler ();

// Job
Jobdetail job = new jobdetail ("computing job", "group 1", typeof (job1 ));

// Trigger
Simpletrigger trigger = new simpletrigger ("trigger 1", "trigger Group 1", 5, new timespan (0, 0, 5 ));

// Associate tasks and triggers
Schedgger. schedulejob (job, trigger );
// Start the task
Scheduler. Start ();

First, initialize a standard scheduler factory stdschedulerfactory and use getscheduler () to create a scheduler. The next step is to declare a job object jobdetail, which has three parameters: Job name, job group name, and job type. Next, instantiate a simpletrigger trigger object. The simpletrigger class has six constructors. The four parameters in the preceding example are: trigger name, trigger Group Name, number of cyclic executions, and execution interval. The scheduler calls the schedulejob method to associate the job object with the trigger. When the trigger is opened, the job can start.

The job job1 to be executed is a class that implements the ijob interface. The ijob interface has only one simple method:

Code
Void execute (jobexecutioncontext context)

Each job to be executed must inherit the ijob interface and implement the execute method.

The following is the definition of job1:

Code
Public class job1: ijob
{
Private int I = 0;
Public void execute (jobexecutioncontext context)
{
Console. writeline (++ I );
}
}

The execution result of the above Code is 6 consecutive 1 (repeated 5 times, plus the first execution, a total of 6 times ).

Next I will introduce the job.

Thoughts, principles, technologies, and applications

References

1. Microsoft Management Solution: Job Scheduling

2. Quartz. net

 

Directory: quartz. NET architecture and source code analysis Series
Next article: quartz. NET architecture and source code analysis series Part 2: Job jobs

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.