Integrated Quartz in Spring:
The configuration of the spring file:
<?xml version= "1.0" encoding= "UTF-8"? ><beansxmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" xsi: schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-3.0.xsd "><bean id=" Quartztask "class=" Com.chen.quartz.QuartzTask "></bean><bean id= "Quartzfactorybean" class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >< Property Name= "TargetObject" ref= "Quartztask" ></property><property name= "Targetmethod" value= " Executequartztask "></property></bean><bean id=" Crontriggerbean "class=" Org.springframework.scheduling.quartz.CronTriggerBean "><property name=" Jobdetail "><ref bean=" Quartzfactorybean "/></property><!--a cron expression with at least 6 (or possibly 7) space-delimited time elements in order: seconds, minutes, hours, days, months, weeks, and years note: due to" date in month " And the "date of the week" two elements mutually exclusive, must be set to one of? --><property Name= "Cronexpression" ><VALUE>0/5 * * * *? </value></property></bean><bean class= " Org.springframework.scheduling.quartz.SchedulerFactoryBean "><property name=" triggers "><list>< Ref bean= "Crontriggerbean"/></list></property></bean></beans>
Java Class for timer execution:
Package Com.chen.quartz;import Java.text.simpledateformat;import Java.util.date;public class QuartzTask {static int Count = 0;public void Executequartztask () {SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss"); System.out.println (Sdf.format (New Date ()) + ":" +count++); /** * @param args */public static void main (string[] args) {//TODO auto-generated method StubSystem.out.println (count++); System.out.println (count++);}}
Cronexpression configuration instructions in Quartz:
Integrated quartz timers in spring and cronexpression configuration instructions in quartz