Download
Official website: http://www.quartz-scheduler.org/
Download steps:
1, click the orange download connection.
2. Click Quartz 2.2.1 Full distribution (release notes) under direct download.
3, click quartz-2.2.1-distribution.tar.gz to download, select any one of the two can.
4. Maven Project Introduction
<dependency> <groupId>Org.quartz-scheduler</groupId> <artifactid>Quartz</artifactid> <version>2.2.1</version></Dependency><dependency> <groupId>Org.quartz-scheduler</groupId> <artifactid>Quartz-jobs</artifactid> <version>2.2.1</version></Dependency>
Example1
This instance is the first instance provided in the official documentation and is annotated as a one by one description for this instance. The current version of Quartz usage is 2.2.1.
1, define task processing class Hellojob implement the Job interface
PackageCom.secbro.job;ImportOrg.quartz.Job;ImportOrg.quartz.JobExecutionContext;ImportOrg.quartz.JobExecutionException;ImportJava.util.Date;/** * Implement the job interface to define the tasks that are specific to the operation * / Public class hellojob implements Job{ @Override Public void Execute(Jobexecutioncontext Jobexecutioncontext)throwsjobexecutionexception {//The task here is to print out the current timeSystem.out.println ("Hello world! - "+NewDate ()); }}
2, the implementation of the task of the processing class
PackageCom.secbro.test;ImportCom.secbro.job.HelloJob;Importorg.quartz.*;ImportOrg.quartz.impl.StdSchedulerFactory;ImportJava.util.Date;/** * Client performing the task * / Public class simpleexample { /** * Define Construction method * / Public Simpleexample() { } Public void Run()throwsschedulerexception {//Log printing, for convenience, this out is replaced by console printingSystem.out.println ("-------Initializing----------------------");//Get a Scheduler instance through SchedulerfactoryStdschedulerfactory SF =NewStdschedulerfactory ();//stands for a quartz independent running containerScheduler Scheduler = Sf.getscheduler (); System.out.println ("-------Initialization complete-----------");//will return a point in time after one minuteDate runtime = Datebuilder.evenminutedate (NewDate ()); System.out.println ("-------scheduling Job-------------------");//Create an Jobdetail instance, this version Jobdetail already exists as an interface (interface), created by JobbuilderJobdetail Jobdetail = Jobbuilder.newjob (Hellojob.class). Withidentity ("Job1","Group1"). build ();//define Schedule rules interfaceTrigger Trigger = Triggerbuilder.newtrigger (). Withidentity ("Trigger1","Group1"). StartAt (Runtime). build ();//Add Jobdetail to Scheduler container, and associate with triggerScheduler.schedulejob (Jobdetail,trigger); System.out.println (Jobdetail.getkey () +"would run at:"+ runtime); Scheduler.start (); System.out.println ("-------Started Scheduler-----------------"); System.out.println ("-------waiting seconds ...-------------");Try{Thread.Sleep (65000L); }Catch(Exception var8) { ; } System.out.println ("-------shutting down---------------------"); Scheduler.shutdown (true); System.out.println ("-------Shutdown complete-----------------"); } Public Static void Main(string[] args)throwsException {Simpleexample example =NewSimpleexample (); Example.run (); }}
3, after the implementation, printing results are as follows
------- Initializing ----------------------------- initialization Complete ------------------ Scheduling Job -------------------group1.Job1 would Run At : Fri June A 16:37:00 CST -------- Started Scheduler ------------------------ Waiting $ seconds... -------------Hello world! - Fri June A 16:37:00 CST -------- shutting Down ---------------------------- Shutdown Complete -----------------Process finished with Exit Code 0
One of the contents for Hellojob timed task printing information.
HelloWorld-FriJun 12 16:37:00CST 2015
At this point, Quartz's download and simple examples have been completed.
Quartz Introduction (i) download and simple examples