Task Scheduler for Java, using cron expressions

Source: Internet
Author: User

Some functions such as timing function and certain methods can be implemented by timing task scheduling framework quartz. The following provides a simple example of implementing the quartz framework of Hello World.

Importorg.quartz.CronExpression;ImportOrg.quartz.CronTrigger;ImportOrg.quartz.Job;ImportOrg.quartz.JobDetail;ImportOrg.quartz.JobExecutionContext;Importorg.quartz.JobExecutionException;ImportOrg.quartz.Scheduler;Importorg.quartz.SchedulerException;Importorg.quartz.SchedulerFactory;Importorg.quartz.impl.StdSchedulerFactory; Public classDiaodutestImplementsJob {@Override Public voidExecute (Jobexecutioncontext context)throwsjobexecutionexception {System.out.println (NewDate () + "God Bless the most handsome!!!" "); }     Public Static voidMain (string[] args) {jobdetail detail=NewJobdetail ("Job1", "group1", Diaodutest.class); Crontrigger Crontrigger=NewCrontrigger ("Job1", "group1"); Try{cronexpression cronexpression=NewCronexpression ("0/1 * * * *?"));            Crontrigger.setcronexpression (cronexpression); Schedulerfactory Factory=Newstdschedulerfactory ();            Scheduler Scheduler; Try{Scheduler=Factory.getscheduler (); Try{scheduler.schedulejob (detail, crontrigger);                Scheduler.start (); } Catch(schedulerexception e) {//TODO auto-generated Catch blockE.printstacktrace (); }            } Catch(schedulerexception e) {//TODO auto-generated Catch blockE.printstacktrace (); }                    } Catch(ParseException e) {//TODO auto-generated Catch blockE.printstacktrace (); }    }}

Task Scheduler for Java, using cron expressions

Related Article

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.