SpringBoot定时任务实现

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;

/**
 * 
 * 类名称:TimerUtil 类描述:定时器任务 创建人:ganluhua 创建时间:08-16, 2020
 * 
 * @version V1.0
 *
 */
@Component
@Configuration
@EnableScheduling
public class DayTimerUtil {

	// 每天凌晨00:01触发
    @Scheduled(cron="0 1 0 * * ?")
//	@Scheduled(cron = "0/5 * * * * ?")
	public void resetData() {
		System.out.println("定时器任务");
	}
	// @Scheduled(cron = "0/5 * * * * ?")//每隔5秒隔行一次
	// public void test2()
	// {
	// System.out.println("job2 开始执行");
	// }
}

参考文章

https://blog.csdn.net/u010827544/article/details/88691848

你可能感兴趣的:(java)