求一套spring boot视频教程

求一套spring boot视频教程,第1张

SpringBoot2.1.6视频教程-加密百度网盘免费资源在线学习  

链接: https://pan.baidu.com/s/1gIJ9MsAMoOBv5k2YAX3-kQ

提取码: b3di

 SpringBoot2.1.6视频教程-加密 第 9 章 Spring Boot 缓存 第 8 章 开发者工具与单元测试 第 7 章 构建 REST 服务 第 6 章 Spring Boot 整合 NoSQL 第 5 章 Spring Boot 整合持久层技术 第 4 章 Spring Boot 整合 Web 开发 第 3 章 Spring Boot 整合视图层技术 第 2 章 Spring Boot 基础配置 第 16 章 微人事项目实战 第 15 章 项目构建与部署 第 14 章 应用监控 第 13 章 企业开发 第 12 章 消息服务 第 11 章 Spring Boot 整合 WebSocket  

第一种比较简单

第二种

@SpringBootApplication

/*

*  开启对定时任务的支持

*  在相应的方法上添加@Scheduled声明需要执行的定时任务。

*/

@EnableScheduling

public class Application {

public static void main(String[] args) {

SpringApplication.run(Application.class, args)

}

}

@SpringBootApplication

/*

*  开启对定时任务的支持

*  在相应的方法上添加@Scheduled声明需要执行的定时任务。

*/

@EnableScheduling

public class Application {

public static void main(String[] args) {

SpringApplication.run(Application.class, args)

}

}

/*把普通pojo实例化到spring容器中,相当于配置文件中的

<bean id="" class=""/>

若想动态改变其值需要继承SchedulingConfigurer

*/

public class AutoSchedule  implements  SchedulingConfigurer{

private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss")

private static final String DEFAULT_CRON = "0/5 * * * * ?"

private String cron = DEFAULT_CRON

@Override

public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {

//            Runnable(线程接口类) 和CronTrigger(定时任务触发器

taskRegistrar.addTriggerTask(() ->{

// 定时任务的业务逻辑

System.out.println("动态修改定时任务cron参数,当前时间:" + dateFormat.format(new Date()))

}, (triggerContext) ->{

// 定时任务触发,可修改定时任务的执行周期

CronTrigger trigger = new CronTrigger(cron)

Date nextExecDate = trigger.nextExecutionTime(triggerContext)

return nextExecDate

})

}

public void setCron(String cron) {

System.out.println("当前cron="+this.cron+"->将被改变为:"+cron)

this.cron = cron

}

}

第三种

@RestController

@Component

public class CrudSchelud  {

//用threadPoolTaskScheduler 类实现对任务的定时调度功能,

//重写CronTrigger触发器,任务却被不断调用3

@Autowired

private ThreadPoolTaskScheduler threadPoolTaskScheduler

private ScheduledFuture<?>future

@Bean

public ThreadPoolTaskScheduler threadPoolTaskScheduler() {

return new ThreadPoolTaskScheduler()

}

@RequestMapping("/startCron")

public String startCron() {

future = threadPoolTaskScheduler.schedule(new MyRunnable(), new CronTrigger("0/5 * * * * *"))

System.out.println("DynamicTask.startCron()")

return "startCron"

}

@RequestMapping("/stopCron")

public String stopCron() {

if (future != null) {

future.cancel(true)

}

System.out.println("DynamicTask.stopCron()")

return "stopCron"

}

@RequestMapping("/changeCron10")

public String startCron10() {

stopCron()// 先停止,在开启.

future = threadPoolTaskScheduler.schedule(new MyRunnable(), new CronTrigger("*/10 * * * * *"))

System.out.println("DynamicTask.startCron10()")

return "changeCron10"

}

private class MyRunnable implements Runnable {

@Override

public void run() {

System.out.println("DynamicTask.MyRunnable.run()," + new Date())

}

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11715405.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存