(1) quartz: A simple Column
Import org. Quartz. crontrigger;
Import org. Quartz. jobdetail;
Import org. Quartz. scheduler;
Import org. Quartz. schedulerexception;
Import org. Quartz. schedulerfactory;
Import org. Quartz. Trigger;
Import org. Quartz. triggerutils;
Import org. Quartz. impl. stdschedulerfactory;
Public class test {
Public static void main (string [] ARGs ){
// Scheduler Factory
Schedulerfactory schedfact = new stdschedulerfactory ();
Try {
// Create a scheduler
Scheduler sched = schedfact. getscheduler ();
// Call the job sjcbjob at, and respectively.
Test. jobdetail (sched, "myjb1", scheduler. default_group, "triger1", sched1. default_group, sjcbjob. class, "0 20 17 **? ");
Test. jobdetail (sched, "myjb2", scheduler. default_group, "triger2", scheduler. default_group, sjcbjob. class, "0 19 17 **? ");
Test. jobdetail (sched, "myjb3", scheduler. default_group, "triger3", scheduler. default_group, sjcbjob. class, "0 18 17 **? ");
// Start the Scheduler
Sched. Start ();
} Catch (schedulerexception e ){
E. printstacktrace ();
}
}
Public static void jobdetail (Scheduler schedil,
String jobname,
String jobgroup,
String trigername,
String trigergroup,
Class jobclass,
String triggertime ){
Try {
// The Job entity jobclass is a job that has the execute method and implements the job interface, throwing a jobexecutionexception
Jobdetail = new jobdetail (jobname, jobgroup, jobclass );
// You must explain the call time and frequency of your job to the scheduler. This is done by job-related triggers.
Trigger trigger = new crontrigger (trigername, trigergroup, triggertime );
// Add the trigger listener to the Scheduler
Schedener. addtriggerlistener (New mytriggerlistener );
// Add a work listener to the Scheduler
Schedener. addjoblistener (New myjobdetaillistener ());
// Match (required)
Trigger. addtriggerlistener ("mytriggerlistener ");
Jobdetail. addjoblistener ("myjoblistener ");
// Set specific jobs and triggers for the Scheduler
// Add the task to the Scheduler
Scheduler. schedulejob (jobdetail, trigger );
} Catch (exception ex ){}
}
}
(2) Perfect Combination of spring and quartz
<! -- Instantiate quartz Bean -->
<Bean id = "startquartz" lazy-init = "false" class = "org. springframework. Scheduling. Quartz. schedulerfactorybean">
<Property name = "triggers">
<List>
<Ref bean = "cutpictime"/>
</List>
</Property>
<Property name = "startupdelay" value = "10000"/> <! -- Starts a job with a delay of 10 seconds -->
</Bean>
<! -- Trigger time -->
<Bean id = "cutpictime" class = "org. springframework. Scheduling. Quartz. crontriggerbean">
<Property name = "jobdetail">
<Ref bean = "cutpic"/>
</Property>
<Property name = "cronexpression">
<Value> 0/10000 ****? </Value>
</Property>
</Bean>
<! -- Called job -->
<Bean id = "cutpic" class = "org. springframework. Scheduling. Quartz. methodinvokingjobdetailfactorybean">
<Property name = "targetobject">
<Ref bean = "cutpicbo"/> <! -- Called job class -->
</Property>
<Property name = "targetmethod">
<Value> cutpic </value> <! -- Call methods in the class -->
</Property>
<Property name = "concurrent" value = "false"/> <! -- Multiple jobs do not run concurrently -->
</Bean>
<! -- Actual job -->
<Bean id = "cutpicbo" class = "com. oppo. ggjg. Bo. cutpicbo"/>