网站百度搜索第一页,河北seo诊断培训,网站制作公司 首推万维科技,网站开发的问题有哪些定时任务
TaskScheduler 任务调度者
TaskExecutor 任务执行者
EnableScheduling//开启定时功能的注释
Scheduled(cron* * * * * * *)//什么时候执行~
cron表达式(秒 分 时 日 月 星期 )
Cron表达式
主启动类加上注解开启任务调度
package com.qf.sping09te…定时任务
TaskScheduler 任务调度者
TaskExecutor 任务执行者
EnableScheduling//开启定时功能的注释
Scheduled(cron* * * * * * *)//什么时候执行~
cron表达式(秒 分 时 日 月 星期 )
Cron表达式
主启动类加上注解开启任务调度
package com.qf.sping09test;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;SpringBootApplication
EnableAsync//开启异步注解功能
EnableScheduling//开启定时功能的注解
public class Sping09TestApplication {public static void main(String[] args) {SpringApplication.run(Sping09TestApplication.class, args);}}业务层代码
package com.qf.sping09test.service;import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;Service
public class ScheduleService {//在一个特定的时间执行这个方法~ Timer//cron表达式(秒 分 时 日 月 星期 )Scheduled(cron 0 24 11 * * ?)public void hello(){System.out.println(hello,你被执行了~);}}不需要导入额外的依赖只需要把 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency
导入springboot内置了定时执行任务的类然后通过注解反射找到这个方法
去按一定的时间去执行这个方法。就是定时执行任务。
这个表达式网上搜就行不用刻意去记记得东西太多了这些去查一下会自动生成只要知道它是用来定时执行方法的就行!!!