Sping Quartz set a timed task

Source: Internet
Author: User

In addition to spring-related jar packages, you need to introduce Quartz-all-1.6.6.jar.

Spring config file adds quartz-bean.xml and Quartz-set.xml

Quartz-bean.xml:

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"Xmlns:tx= "Http://www.springframework.org/schema/tx"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0 . xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP/SPRING-AOP -3.0.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-t X-3.0.xsd ">               <!--Test -    <BeanID= "Testquartztask"class= "Com.tech.jin.quartz.TestQuartzTask"/>    </Beans>

Quartz-set.xml:

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"Xmlns:tx= "Http://www.springframework.org/schema/tx"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0 . xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP/SPRING-AOP -3.0.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-t X-3.0.xsd ">    <!--Scheduled Task Definition -    <Beanclass= "Org.springframework.scheduling.quartz.SchedulerFactoryBean">        < Propertyname= "Quartzproperties">           <Props>              <propKey= "Org.quartz.threadPool.threadCount">50</prop>           </Props>        </ Property>        <!--Auto Start -           < Propertyname= "Autostartup">            <value>True</value>           </ Property>        < Propertyname= "Triggers">            <List>                <refLocal= "Testquartztasktrigger" ></ref><!--Test Automatic Tasks -<!--<ref local= "Transqueryjobtrigger"/> -                            </List>        </ Property>    </Bean>        <!--Test Automatic Tasks -    <BeanID= "Testquartztasktrigger"class= "Org.springframework.scheduling.quartz.CronTriggerBean">        < Propertyname= "Jobdetail">            <refBean= "Testquartztaskjobdetail"/>        </ Property>        < Propertyname= "Cronexpression">             <value>0/10 * * * *?</value>        </ Property>        < Propertyname= "Jobdataasmap">            <Map>                <entryKey= "Jobclass"value= "Testquartztask"/>                <entryKey= "JobName"value= "Test Automatic task"/>            </Map>         </ Property>    </Bean>    <BeanID= "Testquartztaskjobdetail"class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">        < Propertyname= "TargetObject"><refBean= "Testquartztask"/></ Property>            < Propertyname= "Targetmethod"><value>Dotask</value></ Property>           < Propertyname= "Concurrent"value= "false"/>    </Bean>    </Beans>

The class called Testquartztask:

 Package Com.tech.jin.quartz; Import Org.apache.log4j.Logger;  Public class testquartztask {        private Logger Logger = Logger.getlogger (testquartztask.  Class);          Public void Dotask () {        logger.info ("66666666666666666666666");}    }

In addition to this, the configuration for reading the sping configuration file needs to be added in Web. xml: Classpath:spring/quartz-*xml

  < Context-param >    < Param-name >contextconfiglocation</param-name>    <  Param-value>        classpath:spring/applicationcontext.xml;        Classpath:spring/quartz-*xml    </param-value>  </  context-param>

Sping Quartz set a scheduled task

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.