Use the quartz. net2.0 job scheduling framework expression

Source: Internet
Author: User

1. Create a console applicationProgram

2. Create a class, which is a simple task.

 
Public ClassMyjob: quartz. ijob {# RegionIjob MemberPublic VoidExecute (quartz. ijobexecutioncontext context) {console. writeline ("Test"+Datetime. Now. tostring (); // output}# Endregion}

3. The expression is used to execute the task.

         Static   Void Main ( String [] ARGs) {quartz. impl. stdschedulerfactory objstdscheduler = New  Quartz. impl. stdschedulerfactory (); // create a standard scheduling factory quartz. ischeduler objsched = Objstdscheduler. getscheduler (); // get a scheduler objscheduler. Start (); // start the scheduler quartz. ijobdetail objjob = Quartz. jobbuilder. Create <myjob> (). withidentity ( "  Myjob  " , "  Group1  "  ). Build (); // build a job quartz. itrigger objtrigger =New Quartz. impl. triggers. crontriggerimpl ( "  Myjob  " , "  Group1  " , "  30 25 16? * 1, 2, 3, 5, 6, 7 *  "  ); // Use expressions to construct the trigger objschedgger. schedulejob (objjob, objtrigger); // schedule the task} 

Expression description

Example:30 25 16? * 1, 2, 3, 5, 6, 7 * indicates that the task is executed at every day except Wednesday.

 

Meaning of each element in sequence:

1. Seconds seconds (0-60)

2. Minutes minutes (0-60)

3. Hours hour (0-23)

4. Days in day-of-month (0-31)

5. Month (0-11 orJan, Feb Mar, APR, May, Jun, Jul, Aug, SEP, Oct, Nov, Dec)

6. Days (1-7 orSun, Mon, Tue, wed, Thu, Fri, Sat)

7. Year (optional field) year (optional field)

Other notes:

1. The sixth element week, 1 indicates Sunday, 2 indicates Monday, and 7 indicates Saturday, because foreigners calculate the week from Sunday.

2.A single subexpression can contain a range or a list. For example, the day field (here "wed") in the week in the previous example can be replaced with "MON-FRI", "mon, wed, Fri" or even "MON-WED, sat ".

3.Wildcard ('*') can be used to indicate the possible values of "each" in the domain. Therefore, * in the "month" field indicates each month, and * in the day-of-week field indicates "every day of the week ".

4 .'? The 'character can be used in the day-of-month and day-of-week fields to indicate "no value specified ". This is useful when you need to specify the value of one or two domains without setting other domains.

5.The '/' character is used to represent the increment of the value. For example, if the minute domain is put into '123', it indicates "every 15 minutes, starting from 0 ", if '20140901' is used in the intermediate domain, it indicates "every 20 minutes in the hour, starting from 3/20 minutes" or the same format is '3, 3rd '.

6.The 'l' character can be used in day-of-month and day-of-week. This character is short for "last", but has different meanings in the two fields. For example, "l" in the day-of-month field indicates the last day of the month, that is, the 31st day of January 1, January, rather than the 28th day of January 1, February of a leap year. If it is used in day-of-week, it indicates "7" or "sat ". However, if the character in the day-of-week field is followed by another value, it indicates "XXX of the last week of the month ". For example, "6l" or "fril" indicates the last Friday of this month. When you use the 'l' option, do not specify the list or value range. Otherwise, confusion may occur.

7.The 'W' character is used to specify the week closest to the specified day (in the day-of-week domain ). For example, if you specify "15 W" for the Day-of-month field, it indicates the number of weeks closest to the 15th day of the month ".

8.'#' Indicates the week of the month. For example, "6 #3" or "Fri #3" in the day-of-week field indicates "Friday of the third week of the month ".

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.