The use of Spring timers

Source: Internet
Author: User

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

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.