The timing of the mission task springboot

 

On start plus @EnableScheduling inlet, the method requires timing in adding annotations @Scheduled

such as:

package com.gong.spingbootes.service;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Service
public  class ScheduledServcie {
     // seconds, minutes, hours, days, months, days of the week 
    @Scheduled (the cron = "* * * * 0 the FRI-the MON")
     public  void Hello () {
        System.out.println("hell...");
    }
}

@Scheduled main parameters of the cron annotation, there are six values, corresponding to the annotation. The code means: Monday through Friday of the second, performing a method.

Start the server, when the time is to 13:22: 00 , the console will output:

In the example:

@Scheduled (cron = "0,1,2,3,4 * * * * MON-FRI"): Monday to Friday, will run the first 0,1,2,3,4 seconds

@Scheduled (cron = "0-4 * * * * MON-FRI"): Monday to Friday, will run the first 0,1,2,3,4 seconds

@Scheduled (cron = "0/4 * * * * MON-FRI"): Monday to Friday beginning from 0 seconds, performed once every four seconds

Specific reference to the above may form.

 

Guess you like

Origin www.cnblogs.com/xiximayou/p/12298736.html