Job scheduling Framework Quartz Learning Notes (iii)--cron expression

Source: Internet
Author: User
Tags dateformat

The previous two is a simple trigger (Simpletrigger), Simpletrigger can only handle simple events, if you want to be flexible to trigger the task, you need to

Crontrigger this important person.

Crontrigger is also one of the most important features of quartz, by quartz specific cron expression to determine a certain kind of time, can complete similar "November 11, 2011 (God Stick Day, has passed), each Wednesday xxx" complex timing tasks.

Code or old routine, two classes: Simplejob.java and Crontriggerexample.java

It is recommended to run the code first, see the results, and then look at the code

Simplejob.java[Java]  View plain copy import java.text.simpledateformat;   import java.util.calendar;       import org.quartz.job;   import org.quartz.jobexecutioncontext;    import org.quartz.jobexecutionexception;      Public class simplejob  implements Job {           @Override         public void execute (jobexecutioncontext context)                 throws JobExecutionException {            // job  's name             string jobname = context.getjobdetail (). GetKey (). GetName ();                      //   Time of task execution           simpledateformat dateformat = new  simpledateformat ("yyyy  year  MM  month  dd  Day   HH  time  mm  Division  ss   sec ");           String jobRunTime =  Dateformat.format (Calendar.getinstance (). GetTime ());                       //  Output Task performance             system.out.println ("Task  : "  + jobName +  "      " +jobRunTime + "   executed   ");      &nbsp}   }  

Crontriggerexample.java[Java]  View Plain copy import static org.quartz.cronschedulebuilder.cronschedule;   import  static org.quartz.JobBuilder.newJob;   import static  org.quartz.triggerbuilder.newtrigger;      import java.text.simpledateformat;    import java.util.date;      import org.quartz.crontrigger;   Import  org.quartz.JobDetail;   import org.quartz.scheduler;   import  org.quartz.schedulerfactory;   import org.quartz.schedulermetadata;   import  Use of org.quartz.impl.stdschedulerfactory;     /**   * Cron Triggers     */   public class crontriggerexample {           public static void main (String[] args)  throws Exception {            crontriggerexample example = new crontriggerexample ();            example.run ();       }  

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.