The quartz framework is a scheduling framework in Java that can arbitrarily control the start time, end time, time interval, and time schedule of the task execution. While the quartz framework separates task jobs from trigger trigger, a job task can bind multiple trigger triggers at the same time, a loosely coupled state that allows the job to be reused easily.
Quartz framework design to the main classes are divided into three: Scheduler: The main scheduling class, responsible for task initialization, assignment, scheduling job: Represents a task class, which is the implementation of our final logic class Trigger: Triggers, representing the time point of task execution
Or, from the simplest HelloWorld, the use of the quartz framework
Define task Job First
public class Hellojob implements JOB {
@Override public
void execute (jobexecutioncontext jobexecutioncontext) Throws jobexecutionexception {
System.out.println ("Hello World");
}
And then use Scheduler to dispatch the job.
Schedulerfactory factory = new Stdschedulerfactory ();
try {
Scheduler Scheduler = Factory.getscheduler ();
Scheduler.start ();
Jobdetail Jobdetail = Jobbuilder.newjob (Hellojob.class). Withidentity ("Job1", "group1"). Build ();
Trigger Trigger = Triggerbuilder.newtrigger ()
. Withidentity ("Trigger1", "group1")
. Withschedule ( Simpleschedulebuilder.simpleschedule (). RepeatForever (). Withintervalinseconds (). Build
();
Scheduler.schedulejob (Jobdetail, trigger);
} catch (Exception e) {
e.printstacktrace ();
}
This defines a timed task, and every 10s will perform a task of printing Hello World.