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/03 Report--
This article introduces the knowledge of "what are the differences in the performance of common Bean copy frameworks?". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
i. Background
When the volume of business is small, no matter which framework you choose, there is no problem, as long as the function supports ok; but when the amount of data is large, you may need to consider the performance problem; in the actual project, you happen to encounter this problem, which is not only slow, but also found that there will be lock competition, which is especially true for Nip.
The BeanUtils of Spring is used in the project, and the version 3.2.4.RELEASE is relatively old. The main problem is org.springframework.beans.CachedIntrospectionResults.forClass.
/ * Create CachedIntrospectionResults for the given bean class. *
We don't want to use synchronization here. Object references are atomic, * so we can live with doing the occasional unnecessary lookup at startup only. * @ param beanClass the bean class to analyze * @ return the corresponding CachedIntrospectionResults * @ throws BeansException in case of introspection failure * / static CachedIntrospectionResults forClass (Class beanClass) throws BeansException {CachedIntrospectionResults results; Object value; synchronized (classCache) {value = classCache.get (beanClass);} if (value instanceof Reference) {Reference ref = (Reference) value; results = (CachedIntrospectionResults) ref.get ();} else {results = (CachedIntrospectionResults) value } if (results = = null) {if (ClassUtils.isCacheSafe (beanClass, CachedIntrospectionResults.class.getClassLoader ()) | | isClassLoaderAccepted (beanClass.getClassLoader ()) {results = new CachedIntrospectionResults (beanClass); synchronized (classCache) {classCache.put (beanClass, results)) }} else {if (logger.isDebugEnabled ()) {logger.debug ("Not strongly caching class [" + beanClass.getName () + "] because it is not cache-safe");} results = new CachedIntrospectionResults (beanClass); synchronized (classCache) {classCache.put (beanClass, new WeakReference (results)) } return results;}
Looking at the above implementation, every time we get the value, we add a synchronization lock, and it is the global classCache of the lock, which is a bit too much. The subtle thing is that this code is commented, and Google translates it for
We don't want to use synchronization here. Object references are atomic, so we can only make occasional unnecessary lookups at startup.
This probably means that I use it at startup and do not use it frequently, so it is not a problem to use synchronous code blocks.
But in BeanUtils#copyProperties, the egg hurts, and this method is carried out every time, which hurts the heart
Of course, we generally use Spring5+ now, and this code has been modified a long time ago. the new version is as follows, and there is no longer the concurrency problem above.
/ * Create CachedIntrospectionResults for the given bean class. * @ param beanClass the bean class to analyze * @ return the corresponding CachedIntrospectionResults * @ throws BeansException in case of introspection failure * / @ SuppressWarnings ("unchecked") static CachedIntrospectionResults forClass (Class beanClass) throws BeansException {CachedIntrospectionResults results = strongClassCache.get (beanClass); if (results! = null) {return results;} results = softClassCache.get (beanClass); if (results! = null) {return results;} results = new CachedIntrospectionResults (beanClass); ConcurrentMap
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.