- Spring Boot 2.0 Cookbook(Second Edition)
- Alex Antonov
- 104字
- 2021-06-24 19:24:39
How to do it...
- Let's add an @EnableScheduling annotation to the BookPubApplication class, as follows:
@SpringBootApplication @EnableScheduling public class BookPubApplication {...}
- As a @Scheduled annotation can be placed only on methods without arguments, let's add a new run() method to the StartupRunner class and annotate it with the @Scheduled annotation, as shown in the following line:
@Scheduled(initialDelay = 1000, fixedRate = 10000) public void run() { logger.info("Number of books: " + bookRepository.count()); }
- Start the application by executing ./gradlew clean bootRun from the command line so as to observe the Number of books: 0 message that shows in the logs every 10 seconds.
推薦閱讀
- Access 2016數據庫教程(微課版·第2版)
- 數據可視化:從小白到數據工程師的成長之路
- Spark快速大數據分析(第2版)
- Developing Mobile Games with Moai SDK
- Neural Network Programming with TensorFlow
- 數據驅動設計:A/B測試提升用戶體驗
- Spark大數據編程實用教程
- MySQL數據庫技術與應用
- MySQL技術內幕:InnoDB存儲引擎
- Node.js High Performance
- 企業大數據處理:Spark、Druid、Flume與Kafka應用實踐
- 改進的群智能算法及其應用
- MySQL數據庫應用與管理
- Unity for Architectural Visualization
- 代碼的未來