The CronTriggers are more useful than the SimpleTrigger, if we want to performed the job triggering based on the calendar schedules such as "every day", "every weekday" etc. This is also useful when we need to fire jobs in a schedule that is based on the calendar schedule on the exact specified time intervals of SimpleTrigger. Here we will execute an expression that fires at 8:30, 9:30, 10:30, and 11:30 on every Monday and Saturday.
The Cron-Expressions are strings which are used for configuring the instances of CronTrigger. The Cron-Expressions made up of following sub-expressions that performs individual works according to it's schedule and that is separated by the white-space. :
Example: The Cron-expression string is "0 0 10 ? * SUN" that means "every Sunday at 10 am". This example reads only the "SUN" from weekday and replaces to all weekday.
The Wild-cards ('* ' character) that can be used for inserting the every possible value of this field. The '*' character is used in the "Month" field that means "every month" and "Day-Of-Week" field means "every day of the week".
All fields have some specific values that are specified by us. Such as the numbers 0 to 23 for hours, 0 to 59 that is used for minutes and seconds, 0 to 31 for Day-of-Month but here, we should more careful about how many day are used in a month. Months have the specified values between 0 to 11, for this we will use the some string as like: JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV and DEC. Similarly, the Days-of-week has specified values between 1 to 7. Here 1 for Sunday, 2 for Monday, 3 for Tuesday,....... so on. But here we will use the some string for this like: SUN, MON, TUE, WED, THU, FRI and SAT.
The Cron-Expressions are used the '/' character for increments to specify values. If we will put "0/10" in the seconds field that means every 10 seconds will start at second zero and if we will put "0/20" in the Minutes field then it will simply fires every 20 minutes.
The Cron-Expressions are also used the '?' character that allows for the day-of-month and day-of-week fields for specifying "no specific value".
The 'L' character, it is the short form of "last" that allows us for using the day-of -month and day-of-week fields. If we can use the value 'L' in the day-of-month field that means last day of the month like: 31 for January, 28 for February not the leap years. In case of day-of-week field that means "7 stands for SAT".
There are following example of expressions for specify the JavaDOC for CronTrigger:
1.Example: Write an expression to create a trigger that fires ever 10 minutes.
"0 0/10 * * * ?"
2.Example: Write an expression to create a trigger that fires every 10 minutes, at 10 seconds after the minute.
"10 0/10 * * * ?"
(That means each firing after the 10 seconds interval like: 8:00:00am, 8:10:00am,8:20:00am etc.)
3.Example: Write an expression to create a trigger that fires at 9:30, 10:30, 11:30, 12:30 and 13:30 on every Sunday and Saturday.
"0 30 9-13 ? * SUN, SAT"
Liked it! Share this Tutorial