Spring Boot Create a timed task

Source: Internet
Author: User

Spring Boot-based applications create timed tasks don't be too easy, add a @configuration @EnableScheduling annotation to a class, and then add @scheduled (cron = "${" to the method that the class needs to execute regularly. Case.phase.cron} ") annotation. It's OK.

${case.phase.cron} indicates that Case.phase.cron is taken from the application configuration file Application.properties, or from Config-server.

Importjava.util.List;ImportOrg.slf4j.Logger;Importorg.slf4j.LoggerFactory;Importorg.springframework.beans.factory.annotation.Autowired;Importorg.springframework.context.annotation.Configuration;Importorg.springframework.scheduling.annotation.EnableScheduling;Importorg.springframework.scheduling.annotation.Scheduled;/*** Timed Task * to invoke the standard interface of the job status query **/@Configuration @enablescheduling Public classCasephasetaskservice {Private Static FinalLogger Logger = Loggerfactory.getlogger (casephasetaskservice.class); @Scheduled (Cron= "${case.phase.cron}")     Public voidExecscheduledtask () {Logger.info ("Task start ..."); Logger.info ("Task is over!"); }}

Spring Boot Create a timed 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.