Quartz.xml
<?xml version= "1.0" encoding= "UTF-8"?>
<beans xmlns= "Http://www.springframework.org/schema/beans"
xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo= "Http://code.alibabatech.com/schema/dubbo"
xsi:schemalocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/schema/beans /spring-beans-3.2.xsd
Http://code.alibabatech.com/schema/dubbo Http://code.alibabatech.com/schema/dubbo/dubbo. XSD ">
<!--Configure the job Bean --
<bean id= "myJob2" class= "Com.baidu.entity.MyJob2" ></bean>
<!--configuration Jobdetail --
<bean id= "Job" class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >
<property name= "TargetObject" ref= "myJob2"></property>
<property name= "Targetmethod" value= "execute"></property>
</bean>
<!--configuration Crontrigger --
<bean id= "trigger" class= "Org.springframework.scheduling.quartz.CronTriggerFactoryBean" >
<property name= "Jobdetail" ref= "Job" ></property>
<property name= "cronexpression" value= "0/3 * * one-one" ></property>
<!--cron expression seconds, minutes, hours, days, weeks, years, and months. * Means match all? placeholders, which can only be used on dates or days, meaningless--
</bean>
<!--Configuration Scheduler --
<bean id= "Scheduler" class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" >
<!--join Trigger --
<property name= "triggers" >
<array>
<ref bean= "trigger"/>
</array>
</property>
<!--Configure the native properties of the quartz-
<property name= "Quartzproperties" >
<props>
<prop key= "Org.quartz.threadPool.threadCount" >5</prop>
</props>
</property>
<!--Configure how long the IOC container starts, quartz starts executing--
<property name= "Startupdelay" value= "ten" ></property>
</bean>
</beans>
Job Bean
Package com.baidu.entity;
Import Java.text.SimpleDateFormat;
Import Java.util.Date;
Import org.quartz.JobExecutionException;
public class myjob2{
public void execute () throws Jobexecutionexception {
String date = new SimpleDateFormat ("HH:mm:ss"). Format (new date ());
System.out.println ("Do my job at" +date);
}
}
Required JAR Package
<!--timed Quartz--
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
<version>2.2.1</version>
</dependency>
The use of Spring timers