Example:
import java.io.IOException; import org.apache.commons.httpclient.HttpException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; /** * @author yushen ** / @configuration @enablesCheduling @Component public class JobService {private final Log log = LogFactory.getLog(JobService.class); @Autowired abcservice abcser; @scheduled (cron = "0 0 3 * *?") @scheduled (cron = "0 0 3 * *? ) public void calUserCntTask() throws HttpException, IOException {log.info(" Automatic permission task started! ") ); abcser.Job(); Log.info (" Automatic permission task complete!" ); }}Copy the code
Example:
- Run the following command every five seconds: */5 * * * *?
- Run the following command every minute: “0 */1 * * *?
- Execute it at 23:00 every day: “0 0 23 * *?”
- Every day at 1 am: “0 0 1 * *?”
- Once at 1 am on the first day of each month: “0 0 1 1 *?”
- Execute once at 23:00 on the last day of each month: “0 0 23 L *?”
- Every Sunday at 1 a.m. : “0, 0, 1? * L”
- Do it once at 26,29,33: “0 26,29,33 * * *?
- “0 0 0,13,18,21 * *?” is executed at 0,13,18,21 * *?
- “0 0 2 1 *? *”
- Indicates that the operation is executed at 10:15 am every day from Monday to Friday: “0 15 10? * MON-FRI”
- Last Friday of every month 2002-2006 10:15 am execution: “0 15 10? 6L 2002-2006”
Scheduled to introduce
- @Scheduled(cron = “0 0 3 * * ?” )
- Field allowed values allow special characters seconds 0-59, – * / minute 0-59, – * / hour 0-23, – * / date 1-31, – *? / L W C Month 1-12, – * / week 1-7, – *? / L C # 1970-2099, – * /
Continuously updated