1. First, you need to use @EnableScheduling to annotate to *applicatin.java to detect whether there are scheduled tasks.
2. @Scheduled annotation is used to annotate this method as a timed task. Spring will automatically scan this annotation and start the scheduling task.
package com.david.translate.quartz;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.scheduling.annotation.Scheduled;import org.springframework.stereotype.Component;import com.david.translate.service.SysUserService;@Componentpublic class TimeQuartz { @Autowired private SysUserService userService; /** * Execute once in a minute*/ @Scheduled(cron="0 0/1 * * * ?") public void executeFileDownLoadTask() { System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Task execution "+userService.findAll().size()); }}The time configuration of scheduling tasks uses cron expressions. It is recommended to a website that generates expressions online. If you don’t know how to write or are unwilling to write by yourself, you can use this website to generate it directly:
http://cron.qqe2.com/
The screenshot is as follows:
Some commonly used task expression examples:
0 * * * * ? Triggered every 1 minute
0 0 * * * ? Triggered every 1 hour a day
0 0 10 * * ? Triggered once every 10 o'clock
0 * 14 * * ? Triggered every 1 minute between 2 pm and 2:59 pm every day
0 30 9 1 * ? Every month at 9:30 am
0 15 10 15 * ? Triggered at 10:15 am on the 15th of every month
/5 * * * ? Execute every 5 seconds
0 /1 * * ? Execute every 1 minute
0 0 5-15 * * ? Triggered at 5-15 o'clock every day
0 0/3 * * * ? Triggered every three minutes
0 0-5 14 * * ? Triggered every 1 minute between 2 pm and 2:05 pm every day
0 0/5 14 * * ? Triggered every 5 minutes between 2 pm and 2:55 pm every day
0 0/5 14,18 * * ? Triggered every 5 minutes between 2:55 pm and between 6:55 pm and between 6:55 pm and every 5 minutes between
0 0/30 9-17 * * ? Every half hour during working hours from 9 to 5
0 0 10,14,16 * * ? Every day at 10 am, 2 pm, 4 pm
0 0 12 ? * WED means 12 noon every Wednesday
0 0 17 ? * TUES,THUR,SAT Every Tuesday, Thursday and Saturday at 5pm
0 10,44 14 ? 3 WED triggers at 2:10 and 2:44 pm on Wednesdays in March
0 15 10 ? * MON-FRI triggered at 10:15 am Monday to Friday
0 0 23 L * ? Execute once every 23:00 on the last day of each month
0 15 10 L * ? Triggered at 10:15 am on the last day of each month
0 15 10 ? * 6L Triggered at 10:15 am on the last Friday of each month
0 15 10 * * ? 2005 triggered at 10:15 am every day in 2005
0 15 10 ? * 6L 2002-2005 Triggered at 10:15 am on the last Friday of each month from 2002 to 2005
0 15 10 ? * 6#3 Triggered at 10:15 am on the third Friday of each month
Summarize
The above is the SpringBoot scheduling tasks and commonly used task expressions introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!