Spring timed Dispatch

Source: Internet
Author: User

In many cases, it is necessary to use timed scheduling, such as running a crawler at regular intervals to crawl new data, with quartz,spring task and timer

Spring Task can compare it to a lightweight quartz, and it is simple to use, except that there is no need for additional packages outside of spring-related packages

Recommended use of annotation-style implementations

Import Org.springframework.scheduling.annotation.scheduled;import org.springframework.stereotype.component;@ Componentpublic class Webtask {    //every Five seconds    @Scheduled (cron = "0/5 * * * * *?")    public void Taskjob () {        System.out.println ("Test");}    }

In the relevant configuration, add this sentence configuration, no additional parameters

<task:annotation-driven/>

The specific analysis of Cron is as follows

Field      Allow value     allowed special characters sec       0-59        ,-*/min       0-59        ,-*/hour      0-23        ,-*/Date      1-31        ,-*?/L W C Month Part      1-12 or Jan-dec     ,-*/week      1-7 or Sun-sat      ,-*?/L C #年 (optional) Leave       blank, 1970-2099       ,-*/
View Code

Quartz

 

Spring timed Dispatch

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.