You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/07/01 03:16:05 UTC

[GitHub] [dubbo] stonelion commented on a diff in pull request #10229: refactor: optimize ExtensionLoader code style

stonelion commented on code in PR #10229:
URL: https://github.com/apache/dubbo/pull/10229#discussion_r911582889


##########
dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java:
##########
@@ -436,18 +425,7 @@ public T getExtension(String name, boolean wrap) {
         if ("true".equals(name)) {
             return getDefaultExtension();
         }
-        final Holder<Object> holder = getOrCreateHolder(name);
-        Object instance = holder.get();
-        if (instance == null) {
-            synchronized (holder) {
-                instance = holder.get();
-                if (instance == null) {
-                    instance = createExtension(name, wrap);
-                    holder.set(instance);
-                }
-            }
-        }
-        return (T) instance;
+        return cachedInstances.computeIfAbsent(name, (k) -> createExtension(k, wrap));

Review Comment:
   The method computeIfAbsent of ConcurrentHashMap is atomic. That function is applied at most once per key.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org