J2EE scheduler (quartz)

Source: Internet
Author: User

(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"/>

 

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.