In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you an example analysis of the dynamic change of cron time of spring quartz scheduled tasks. The content is concise and easy to understand, which can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
The cron time of dynamically setting quartz timing task is: xml mode and database table mode, and these two methods need to add a lot of code and data table to the existing timing task, so a relatively simple and practical method is found on the Internet, but this method is not intelligent enough, and the service needs to be restarted every time after modifying the timing task time. If you want to freely control the execution of scheduled tasks in the project, please refer to the xx-job task scheduling project.
Dynamically setting the cron time of quartz scheduled tasks refers to the SchedulingConfigurer interface, and you need to add the annotation @ EnableScheduling to the implementation class. Note: @ EnableScheduling requires a higher version of Spring. The version of spring needs to be above 4.2.5. If it is a lower version, it will not take effect.
1. First set the execution time of scheduled tasks in the configuration file
# set the execution time format conTestTime:0/20 *?
two。 Write task execution classes
@ Component@EnableSchedulingpublic class QuertzJobTask implements SchedulingConfigurer {private static final Logger log = LoggerFactory.getLogger (QuertzJobTask.class); / / read the setting time @ Value ("${conTestTime}") String indSchedulerJobTime in the configuration file @ Override public void configureTasks (ScheduledTaskRegistrar scheduledTaskRegistrar) {scheduledTaskRegistrar.addTriggerTask (new Runnable () {@ Override public void run () {/ / execute task logic log.info ("execution time:" + indSchedulerJobTime) }}, new Trigger () {@ Override public Date nextExecutionTime (TriggerContext triggerContext) {/ / task trigger, you can modify the task execution cycle CronTrigger trigger = new CronTrigger (indSchedulerJobTime); Date nextExec = trigger.nextExecutionTime (triggerContext); return nextExec;}});}}
After the task starts, you can view the log information printed by the tasks it performs on the console.
The above is an example analysis of the dynamic change of cron time in spring quartz scheduled tasks. have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.