QUARTZ cron Expressions

Source: Internet
Author: User

Use quartz cron every time to check manual document;
(Uri:http://quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger)

For the fourth day of month and sixth days of week often take time, here's a brief summary

* * * * * * (year optional)
┬┬┬┬┬┬
││││││
││││││
│││││└─────day of Week (0-7) (0 or 7 are Sun, or use names)
││││└──────────month (1-12)
│││└───────────────day of month (1-31)
││└────────────────────hour (0-23)
│└─────────────────────────min (0-59)
└────────────────────────seconds
Wild-cards (the * character) can be used to say "every" possible value of this field.
Therefore the * character in the "month" field simply means "every month".
A ' * ' in the Day-of-week field would therefore obviously mean "every day of the Week".

The '? ' character is allowed for the Day-of-month and Day-of-week fields.
It is used to specify "no specific value". This is useful if you are need to specify something in one of the.


In order to explain clearly "?" The use of characters, another paragraph

Field Name Mandatory allowed Values allowed special characters
Seconds YES 0-59,-*/
Minutes YES 0-59,-*/
Hours YES 0-23,-*/
Day of month YES 1-31,-*? /L W
Month YES 1-12 or JAN-DEC,-*/
Day of week YES 1-7 or Sun-sat,-*? L
Year NO empty, 1970-2099,-*/

You can see that only the fourth to sixth two locations allow the use of "?"
Which means the 2 locations are interdependent.
?( "No specific value")-Useful when you need to specify something in one of the the the the the the the the the the the the and the the "the" the which is character, and not the allowed R. For example, if I want my trigger to fire in a particular day of the month (say, the 10th), but don ' t care The week that happens to be, I would put "ten" in the Day-of-month field, and "?" in the Day-of-week field. See the examples below for clarification.

So once the "?" is used, it means that the field does not work, and the corresponding other field works;


So:
1. Configure a task to run daily at 2 o'clock in the morning to make the report as of the day, but the weekend because no one on duty, so do not need to generate a report, this expression is
0 0 2? * Mon-fri
2. Configure a task to run at 11 o'clock on the last day of each month
0 0 L *?



What if you want to use the database to drive this time? May I ask the following prawn practices:

Dec 22nd, 01:53 AM #2 Siva Krishna
Hello,

I got almost similar requirement, making the schedulers as DB driven, and handled it in the following.

I created a new UI that takes start time & interval time and saves them in DB. Then a method is called to refresh the given jobs/schedulers.

This is the snippet.

Code:
try {
Scheduler = (Stdscheduler) Context.getbean (Schedulervo.getschedulername ());
Triggernames = new string[] {};

if (scheduler! = NULL) {
try {
Throws Schedulerexception
Triggernames = Scheduler.gettriggernames ("DEFAULT");
Triggername = triggernames.length > 0? Triggernames[0]: "";
Trigger = (Crontrigger) scheduler.gettrigger (triggername, "DEFAULT");
if (trigger! = NULL) {
Throws ParseException
Trigger. setcronexpression(Getcronexpression (Schedulervo.getstarttime (), Schedulervo.getinterval ()));

Throws Schedulerexception
Scheduler. Reschedulejob(Triggername, "DEFAULT", trigger);
}
} catch (Schedulerexception e) {
Logger.error (e);
} catch (ParseException e) {
Logger.error (e);
}
}
} catch (Nosuchbeandefinitionexception e) {
Logger.error (e);
}


Computing the cronexpression with this method.

Code:
private string Getcronexpression (string startTime, string interval) {
String cronexpression = "";
if ("0". Equals (startTime) | | "0". Equals (interval)) {
Default trigger runs at 10AM & 10PM
Cronexpression = "0 0 10/12 * *?";
} else {
Cronexpression = "0 0" + startTime + "/" + Interval + "* *?";
}
return cronexpression;
}
As I need to run the job every day and isn't concerned about minutes the above approach worked for me.

Hope This gives a idea to you.

QUARTZ cron Expression

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.