當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring Boot笔记-线程池调度计划仅运行一次
生活随笔
收集整理的這篇文章主要介紹了
Spring Boot笔记-线程池调度计划仅运行一次
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
這里是有這樣的一個(gè)需求,啟動(dòng)spring?boot后用一個(gè)新線程,跑一次就可以了,首先是線程池申請(qǐng)和配置:
@Configuration @EnableAsync public class AsyncConfiguration {@Bean("TaskExecutor")public Executor asyncExecutor(){ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();executor.setCorePoolSize(5);executor.setMaxPoolSize(10);executor.setQueueCapacity(500);executor.setKeepAliveSeconds(60);executor.setThreadNamePrefix("TaskExecutor Async");executor.initialize();return executor;} }然后配置調(diào)度:
@Configuration @EnableScheduling public class UpdateScheduleTask {@AutowiredXXXXXXX xxxxxxx;@Scheduled(initialDelay = 1000, fixedRate = Long.MAX_VALUE)private void updateCache() throws InterruptedException {//To do something...}這里要主要的@Scheduled()中需要填寫initialDelay?=?1000,而fixedRate為Long.MAX_VALUE。
總結(jié)
以上是生活随笔為你收集整理的Spring Boot笔记-线程池调度计划仅运行一次的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android安全笔记-进程间通信基本概
- 下一篇: Qt文档阅读笔记-Q_INVOKABLE