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