Spring 4 + Quartz Integration Example

Source: Internet
Author: User

Step 1:configure Jobs in Quartz Scheduler

A:using Methodinvokingjobdetailfactorybean

<bean id= "Simplejobdetail" class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" ><property name= "TargetObject" ><bean class= "Com.job.Task"/></property><property name= " Targetmethod "value=" job "/><property name=" concurrent "value=" true "/></bean>
TargetObject the class to execute
Targetmethod to execute the methods in the class
Concurrent immediate execution immediately (when, after class instantiation)

b:using Jobdetailfactorybean

<bean id= "Complexjobdetail" class= "Org.springframework.scheduling.quartz.JobDetailFactoryBean" >< Property Name= "Jobclass" value= "Com.scheduled.ScheduledJob"/><property name= "Jobdatamap" ><map>< Entry key= "task" value-ref= "task" ></entry></map></property><property name= "durability" Value= "true"/></bean>

Jobclass the class to be executed by the configuration task

Jobdatamap Configuring parameter settings in the execution class

Step 2:configure Triggers to being used in Quartz Scheduler

A:simple Trigger, using Simpletriggerfactorybean

<bean id= "Simpletrigger" class= "Org.springframework.scheduling.quartz.SimpleTriggerFactoryBean" >< Property Name= "Jobdetail" ref= "Simplejobdetail"/><property name= "Startdelay" value= "/><property" Name= "Repeatinterval" value= "/></bean>"

Repeatinterval: This triggers the way, the configured time, 2 seconds trigger once.

B:cron Trigger, using Crontriggerfactorybean

<bean id= "Crontrigger" class= "Org.springframework.scheduling.quartz.CronTriggerFactoryBean" ><property Name= "Jobdetail" ref= "Complexjobdetail"/><property name= "cronexpression" value= "0/5 * *? * Sat-sun "/></bean>

Cronexpression:

Examples of some cron expressions
Meaning of an expression
0 0 10,14,16 * *? Daily 10 o'clock in the morning, 2 o'clock in the afternoon and 4 o'clock in the afternoon
0 0,15,30,45 * 1-10 *? Every 15 minutes in the first 10 days of each month
30 0 0 1 1? 2012 at midnight on January 1, 2012, 30 seconds.

Step 3:configure Schedulerfactorybean that creates and configures Quartz Scheduler

<bean class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" ><property name= "Jobdetails" ><list><ref bean= "Simplejobdetail"/><ref bean= "Complexjobdetail"/></list></ Property><property name= "triggers" ><list><ref bean= "Simpletrigger"/><ref bean= " Crontrigger "/></list></property></bean>

Finally integrated.

Configuration requirements:

Spring 4 + version

Quartz version 2 or more

Learn from: http://websystique.com/spring/spring-4-quartz-scheduler-integration-example/

Spring 4 + Quartz Integration Example

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.