原来在刚学习的时候也学了定时器,但是一直没用过,还觉得挺难的。。。
最近终于使用了才知道原来那么简单。。。
在一个方法上添加 Scheduled注解 然后 通过在线生成corn表达式 来在想要的时间执行你的方法
当然类要加到spring的管理中,通过Component注解
@Scheduled(cron = “0 * * * * ?”)
@Component
@Slf4j
public class ScheduleTask {
/**
*定时器
*/
@Scheduled(cron = "0 * * * * ?")
public void start(){
}
}