Using quartz to implement timer functions

Source: Internet
Author: User

Import two packages first
1     <Dependency>2         <groupId>Org.quartz-scheduler</groupId>3         <Artifactid>Quartz</Artifactid>4         <version>2.2.2</version>5     </Dependency>6     <Dependency>7         <groupId>Org.quartz-scheduler</groupId>8         <Artifactid>Quartz-jobs</Artifactid>9         <version>2.2.2</version>Ten     </Dependency>

Then write a class used as the timer class, and write a method for the timer to execute the method:
1  PackageCom.practice.prac.service.Impl;2  3 Importorg.springframework.stereotype.Component;4  5 @Component6  Public classTesttime {7  8      Public voidprint () {9System.out.println ("----------");Ten     } One}

Here is the Testtime class and the Print method that defines the following beans in the XML file:
1 <!--The following is the Quartz implementation timer -2  3     <!--indicates the class as a timer -4     <BeanID= "Testtime"class= "Com.practice.prac.service.Impl.TestTime"></Bean>5     <!--Configure the corresponding information -6     <BeanID= "Testtimedetail"7 class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">8         <!--Specifying task Classes -9         < Propertyname= "TargetObject"ref= "Testtime" />Ten         <!--specify how the task executes - One         < Propertyname= "Targetmethod"value= "Print" /> A     </Bean> -     <!--Configuring triggers - -     <BeanID= "Testtimetrigger" the class= "Org.springframework.scheduling.quartz.CronTriggerFactoryBean"> -         < Propertyname= "Jobdetail"ref= "Testtimedetail" /> -         <!--run once every 5 seconds - -         < Propertyname= "Cronexpression"value= "0/5 * * * *?" /> +     </Bean> -   +     <Beanclass= "Org.springframework.scheduling.quartz.SchedulerFactoryBean"> A         < Propertyname= "Triggers"> at             <List> -                 <!--<ref bean= "Examplejobtrigger"/> - -                 <refBean= "Testtimetrigger" /> -             </List> -         </ Property> -     </Bean>

Where the name corresponds to ref, specify the task class and the method that specifies the task execution. The timing trigger is defined at the cronexpression of the trigger, and the specific expression meaning is in another article.

Using quartz to implement timer functions

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: 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.