定时任务
在启动类上面加上 @EnableScheduling即可开启定时
1 | @SpringBootApplication |
创建定时任务实现类
①
1 | @Component |
②
1 | @Component |
结果如下:
1 | this is scheduler task runing 0 |
参数说明:
1 | @Scheduled 参数可以接受两种定时的设置,一种是我们常用的cron="*/6 * * * * ?",一种是 fixedRate = 6000,两种都表示每隔六秒打印一下内容。 |
定时任务
在启动类上面加上 @EnableScheduling即可开启定时
1 | @SpringBootApplication |
创建定时任务实现类
①
1 | @Component |
②
1 | @Component |
结果如下:
1 | this is scheduler task runing 0 |
参数说明:
1 | @Scheduled 参数可以接受两种定时的设置,一种是我们常用的cron="*/6 * * * * ?",一种是 fixedRate = 6000,两种都表示每隔六秒打印一下内容。 |