Spring integrates TimerTask to realize scheduled task scheduling
I preface
Recently, timed tasks have been used in the company's projects. This blog will summarize the timed tasks of TimerTask. In fact, TimerTask is not used much in actual projects, because it cannot run at a specified time and can only run the program at a certain frequency
II TimerTask
Timer in JDK is a timer class, which can be configured for specified scheduled tasks TimerTask in JDK is a scheduled task class, which implements the runnable interface and is an abstract class. We can inherit this class to implement scheduled tasks
III Integrate spring
Two core classes: scheduledtimertask and timerfactorybean. Scheduledtimertask is the wrapper implementation of TimerTask. Trigger information can be defined for this task through this class The timerfactorybean class allows spring to create triggers using configuration and automatically create timer instances for a specified set of scheduledtimertask beans
1. Import jar package: spring.com jar,commons-logging. jar 2. Scheduled scheduling service class:
3. Core configuration:
4. Test class:
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.