Simple example of springboot Integrated Quartz timing Task

Source: Internet
Author: User

POM. XML file

<!--timer task quartz need to import coordinates--        <dependency>            <groupId>org.quartz-scheduler</groupId>            <artifactId>quartz</artifactId>            <version>1.8.5</version>        </dependency >

Similar to the controller code:

 Package Com.xiaowu.quartz.demo;import;import Org.springframework.scheduling.annotation.scheduled;import org.springframework.stereotype.component;/*** * * Quartz set the project global Schedule Task * * @Component The meaning of annotations refers to the components, we can use this annotation to annotate when the component is not well categorized. General public methods I will use this note * * * @author WQ * */@Componentpublic class Quartzdemo {@Scheduled (cron = "0 0/1 * * * *?")//per minute    The clock executes a public void work () throws Exception {System.out.println ("Perform dispatch task:" +new Date ()); } @Scheduled (fixedrate = 5000)//Execute public void play () throws Exception {System.out.println ("execute Q") every 5 seconds    Uartz Timer Task: "+new Date ()); } @Scheduled (cron = "0/2 * * * * *?")//every 2 seconds public void dosomething () throws Exception {System.ou    T.println ("Perform a scheduled task every 2 seconds:" +new Date ()); } @Scheduled (cron = "0 0 0/1 * *?")//hourly execution of public void Gowork () throws Exception {System.    Out.println ("Timed tasks performed once per hour:" +new Date ()); }                }

Start the Springboot project and you can.

public static void Main (string[] args) { (chapter1application.class, args);    }

As follows:

Simple example of springboot Integrated Quartz timing 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: 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.