Quartz Implementing a regular Run program (Java)

Source: Internet
Author: User


Package
Quartz;ImportJava.text.SimpleDateFormat;Importjava.util.Date;ImportOrg.quartz.Job;ImportOrg.quartz.JobExecutionContext;Importorg.quartz.JobExecutionException; Public classMyJobImplementsJob {@Override Public voidExecute (jobexecutioncontext arg0)throwsjobexecutionexception {simpledateformat sdf=NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss SSS"); System.out.println ("The current time is:" + sdf.format (NewDate ())); System.out.println ("Hello World"); }}
 PackageQuartz;ImportJava.text.SimpleDateFormat;Importjava.util.Date;ImportOrg.quartz.CronScheduleBuilder;ImportOrg.quartz.CronTrigger;ImportOrg.quartz.JobDetail;ImportOrg.quartz.Scheduler;Importorg.quartz.SchedulerFactory;Importorg.quartz.impl.StdSchedulerFactory;Import StaticOrg.quartz.JobBuilder.newJob;Import StaticOrg.quartz.TriggerBuilder.newTrigger;Import StaticOrg.quartz.CronScheduleBuilder.cronSchedule; Public classTimeupdate { Public voidGo ()throwsException {//first, it is necessary to obtain a schedularSchedulerfactory SF =Newstdschedulerfactory (); Scheduler Scheduler=Sf.getscheduler (); //JOB1 will be executed every 20 secondsJobdetail job = Newjob (MyJob.class). Withidentity ("Job1", "group1"). build (); Crontrigger Trigger= Newtrigger (). Withidentity ("Trigger1", "group1"). Withschedule (Cronschedule ("0/20 * * * *?") . Build (); Date ft=scheduler.schedulejob (Job, trigger); SimpleDateFormat SDF=NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss SSS"); System.out.println (Job.getkey ()+ "has been scheduled to execute:" +sdf.format (ft)+ "and repeat with the following repeating rules:" +trigger.getcronexpression ());    Scheduler.start (); }     Public Static voidMain (string[] args)throwsException {timeupdate test=Newtimeupdate ();    Test.go (); }}

/*--------------------------------------0 0 12 * *? 12-point Trigger 0 15 10 per day?           * * Daily 10:15 Trigger 0 15 10 * *? Trigger 0 15 10 * * per day 10:15? * Daily 10:15 Trigger 0 15 10 * *?            2005 2005 Daily 10:15 Trigger 0 * 14 * *?          Every afternoon from 2 to 2:59 per minute trigger 0 0/5 14 * *?       Every afternoon from 2 to 2:59 (the whole point starts, every 5 minutes trigger) 0 0/5 14,18 * *?          Every afternoon from 2 to 2:59 (the whole point starts, every 5 minutes trigger) every afternoon from 18 to 18:59 (the whole point starts, every 5 points trigger) 0 0-5 14 * *? 0 10,44 14 per minute from 2 to 2:05 every afternoon? 3 WED March every Wednesday pm 2:10 and 2:44 trigger 0 15 10?          * Mon-fri from Monday to Friday every morning 10:15 trigger 0 15 10 15 *?           15th 10:15 A.M. per month, trigger 0 L *? 10:15 trigger on the last day of the month 0 15 10? * 6L of the last week of the month of Friday 10:15 trigger 0 15 10? * 6L 2002-2005 from 2002 to 2005 the last week of the month of Friday 10:15 trigger 0 15 10?          * 6#3 starts in Friday of the third week of the month 0 0 12 1/5 *?         The first noon of each month starts every 5 days and triggers 0 11 11 11 11? November 11 11:11 Trigger (Singles Day)--------------------------------------*/  

The online cron Expression Builder address is: http://www.pdtools.net/tools/becron.jsp

Quartz Implementing a regular Run program (Java)

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.