关于springboot的定时器配置
关于springboot的定时器:
比较重要的两个注解:
@EnableScheduling:标注启动定时任务。
@Scheduled(fixedRate = 1000 * 30) 定义某个定时任务。
案例:
@Component
@Configurable
@EnableScheduling
public class ScheduledTasks{
@Scheduled(fixedRate = 1000 * 30)
public void reportCurrentTime(){
System.out.println ("Scheduling Tasks Examples: The time is now " + dateFormat ().format (new Date ()));
}
//每1分钟执行一次
@Scheduled(cron = "0 */1 * * * * ")
public void reportCurrentByCron(){
System.out.println ("Scheduling Tasks Examples By Cron: The time is now " + dateFormat ().format (new Date ()));
}
private SimpleDateFormat dateFormat(){
return new SimpleDateFormat ("HH:mm:ss");
}
}
|
表达式 | 意义 | |
|---|---|---|
| <wiz_code_mirror>
|
<wiz_code_mirror>
|
|
| <wiz_code_mirror>
|
<wiz_code_mirror>
|
|
| <wiz_code_mirror>
|
<wiz_code_mirror>
|
|
| <wiz_code_mirror>
|
<wiz_code_mirror>
|
|
| <wiz_code_mirror>
|
<wiz_code_mirror>
触发 |
|
| <wiz_code_mirror>
|
<wiz_code_mirror>
|
|
| <wiz_code_mirror>
|
<wiz_code_mirror>
|
|
| <wiz_code_mirror>
|
<wiz_code_mirror>
|
|
| <wiz_code_mirror>
|
<wiz_code_mirror>
|
|
| <wiz_code_mirror>
|
<wiz_code_mirror>
|
|
| <wiz_code_mirror>
|
<wiz_code_mirror>
|
|
| <wiz_code_mirror>
|
<wiz_code_mirror>
|
|
| <wiz_code_mirror>
|
<wiz_code_mirror>
|
|
| <wiz_code_mirror>
|
<wiz_code_mirror>
|
|
| <wiz_code_mirror>
|
<wiz_code_mirror>
|
|
| <wiz_code_mirror>
|
<wiz_code_mirror>
|

浙公网安备 33010602011771号