zh-hongda

搜索引擎-Springboot定时任务

Springboot定时任务

1、添加定时任务注解

@SpringBootApplication
@EnableScheduling
public class Application{

    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
    }

}

2. 使用@Scheduled()定时

@Component
public class SaticScheduleTask {

    //添加定时任务
    //@Scheduled(cron = "0/5 * * * * ?")
    //或直接指定时间间隔,例如:5秒
    //@Scheduled(fixedRate=5000)
    @Scheduled(fixedRate=5000)
    public static void configureTasks() {
        String filePath = "C:/Users/hongda/Desktop/ik.conf"; // 文件路径
        TestIO obj = new TestIO();
        obj.write(filePath, obj.read(filePath)); // 读取修改文件
    }

}