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 > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you about the solution to the problem of springboot2 integration lettuce startup jam, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Preface
EasyCache upgrade is compatible with Springboot2. A business system always gets stuck when it starts, and finally throws a timeout exception, as shown below:
Java.util.concurrent.TimeoutException: null at java.util.concurrent.FutureTask.get (FutureTask.java:205).
The springboot version is 2.2.x, the lettuce version is 2.2.x, and the lettuce version is 5.2.x. If you don't use the jedis client, the problem must be lettuce.
Analyze the reasons
If this problem occurs online, you will use jstack to check the situation of the thread, and it is more convenient to debug the idea locally. Some of the information found by the thread in lettuce is as follows:
"lettuce-kqueueEventLoop-7-114257" daemon prio=5 tid=0x4c nid=NA waiting for monitor entry
Java.lang.Thread.State: BLOCKED
Waiting for main@1 to release lock on (a java.util.concurrent.ConcurrentHashMap)
At org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:208)
At org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java:321)
....
The error in the first line is blocked while getting Bean, indicating that the lock is not released when there is a place to get Bean. At the break point in this place, it was found that the SamplerAutoConfiguration of spring-cloud-sleuth had a lock and not released when it acquired the bean. The source code is as follows
Protected static class RefreshScopedSamplerConfiguration {public Sampler defaultTraceSampler (SamplerProperties config) {return samplerFromProps (config);}}
When @ RefreshScope gets the proxy class, if it is the @ PostConstruct method, the bean cannot be loaded, so the lock has not been released. So guess, before the container is started, there is a place to call lettuce's Bean, resulting in circular dependencies.
The recurrence of the pit and its solution
Run the following code, and the error occurs, exactly the same as the problem with the business system, and validates the above conjecture. The workaround is to call the init method after the container starts. (this problem also occurs when using InitializingBean in practice)
Public class SpringDataTestService {private StringRedisTemplate stringRedisTemplate; / / @ EventListener (MainContextRefreshedEvent.class) public void init () {String s = stringRedisTemplate.opsForValue () .get ("gateway:ab-test:config"); System.out.println (s);}} above is the solution to the problem of springboot2 integrating lettuce startup stuck. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please 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.