In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "springboot how to solve the concurrency problem caused by multiple deploy execution schedule timers". The explanation in the article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "springboot how to solve the concurrency problem caused by multiple deploy execution schedule timers".
Springboot deploys multiple deploy of the same service. When there is a timer in the service, once the timer is triggered, the service will execute at the same time, resulting in concurrency problems. Solution:
1. Add @ Profile annotation to the timer class to specify that the instance executes the timer.
@ Component@Configuration@EnableScheduling / / 1 Start the timing task @ Profile ("deploy01") public class ScheduleTaskService {....}
It is easy to operate and flexible. You only need to add the @ Profile annotation, but its limitations are obvious: the timer processing class is loaded only when the service is specified as deploy01, and cannot be executed once the deploy01 is dead or not started. So it doesn't achieve high availability.
two。 Using redis caching mechanism
@ Scheduled (cron = "000 String deployKey= 1 * *?") / / execute public void insertPriRecoverCall () throws InterruptedException {String deployKey= "deployName" every hour; redisService.set (deployKey,deployId,1,TimeUnit.HOURS); Object o = redisService.get (deployKey); if (ostatic null) {String deployName = o.toString () If (deployId.equals (deployName)) {logger.info (deployName+ "is running."); / Business Code}}
First get the service instance Id and cache it in redis. Redis is the caching mechanism for key-value key-value pairs. Only one deployId is retained under the same key, and then the deployId in the cache is compared with the service instance id. The same will continue to execute the business code, while the difference will be filtered directly. This can not only prevent concurrency problems, but also achieve high availability.
Thank you for your reading, the above is the content of "springboot how to solve the concurrency problem caused by multiple deploy execution schedule timers". After the study of this article, I believe you have a deeper understanding of how springboot solves the concurrency problem caused by multiple deploy execution schedule timers, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.