SpringBoot @Scheduled regular tasks

Ado

First introduced pom-dependent

        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>2.2.1</version>
        </dependency>

Springboot startup class

package com.jzb;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class HebeiApplication {

    private static final Logger LOGGER = LoggerFactory.getLogger(HebeiApplication.class);
    public static void main(String[] args) {

        SpringApplication.run (HebeiApplication. Class , args); 
        logger.info ( "the Application started successfully ..." ); 
    } 

}

New execution classes controller.java

@Component
 public  class Controller { 

    Private  static  Final Logger Logger = LoggerFactory.getLogger (Controller. Class );
 
   / **
    * Timing 5 seconds
    * / @Scheduled (the cron
= "* / * * *. 5 *?" ) Public void Scheduled () { the try { logger.info ( "scheduled task is being executed ..." ); } the catch (exception E) { logger.error ( "exception occurs scheduled tasks: {}" , E); } } }

Above it

 

Detailed cron expression
a cron expression of at least 6 (and possibly 7) has time elements separated by spaces. By order:

Sec (0 to 59)
min (0 - 59)
3 hours (0 to 23)
four days (0 to 31)
May (0 to 11)
6 weeks (1 ~ 7 1 = SUN or SUN, MON, TUE, WED , THU, FRI, SAT)
Year (1970-2099)
in which each element can be a value (e.g., 6), a continuous section (9-12), a time interval (8-18 / 4) (/ indicates every 4 hours), a list of (1,3,5), the wildcard. As the "day of the month" and "date of the week," these two elements are mutually exclusive, and must be for one of the settings. Instance:

Executed once every 5 seconds:? / 5 * * *
every one minute to perform a:? 0/1 * *
00 * * 10,14,16 day 10:00, 14:00, 4:00?
00 / 309-17 * *? inward nine to five hours every half hour
0 0 12? * WED 12:00 every Wednesday expressed
"0012 * *?" 12:00 every day trigger
"01510? * * "10:15 am every day trigger
" 01510 * *? "10:15 am every day trigger
" 01510 * * *? "10:15 am every day trigger
" 01510 * *? 2005 "in 2005 every morning 10:15 triggering
"0 * 14 * *?" triggers during the day at 2:00 pm to 2:59 pm every minute
"0 0/5 14 * *?" during the 2:00 to 2:55 pm every day of trigger every 5 minutes
"0 0/5 * 14, 18 *?" during the 2:00 to 2:55 every afternoon and trigger every 5 minutes 6:00 to 6:55 pm during the
"00-514 * *?" trigger per minute during the day at 2:00 pm to 2:05 pm
"0 10,44 14? 3 WED" March of the year Wednesday afternoon 2:10 and 2:44 trigger
"0 15 10? * MON- FRI "Monday to Friday 10:15 am to trigger
" 0151015 *? "15th of each month at 10:15 am triggering
" 0 15 10 L *? The last day of each month at 10:15 am triggering
"0 15 10? * 6L" the last Friday of each month at 10:15 am triggering
"0 15 10? * 6L 2002-2005 " 2002 years to 2005, the last Friday of each month at 10:15 am triggering
"015 ? 10 * 6 # 3 "is the third Friday of each month at 10:15 am triggered
online cron expression builder: http: //qqe2.com/cron/index

Guess you like

Origin www.cnblogs.com/xikui/p/12168213.html