You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2024/07/04 07:15:00 UTC

(dubbo) branch 3.2 updated: Sync spring init actions to prevent parallel init (#14371)

This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.2 by this push:
     new 79a1cca4ef Sync spring init actions to prevent parallel init (#14371)
79a1cca4ef is described below

commit 79a1cca4ef1d583d2ae2c8e3f16eeea5881712cc
Author: Albumen Kevin <jh...@gmail.com>
AuthorDate: Thu Jul 4 15:14:55 2024 +0800

    Sync spring init actions to prevent parallel init (#14371)
    
    * Sync spring init actions to prevent parallel init
    
    * fix code
    
    * fix code
---
 .../apache/dubbo/config/spring/ReferenceBean.java  | 27 ++++++++++++++--------
 .../context/DubboConfigApplicationListener.java    |  2 +-
 2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java
index dc474498d6..3bbd3ce241 100644
--- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java
+++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java
@@ -148,7 +148,7 @@ public class ReferenceBean<T>
     private MutablePropertyValues propertyValues;
 
     // actual reference config
-    private ReferenceConfig referenceConfig;
+    private volatile ReferenceConfig referenceConfig;
 
     // ReferenceBeanManager
     private ReferenceBeanManager referenceBeanManager;
@@ -423,15 +423,22 @@ public class ReferenceBean<T>
 
     private Object getCallProxy() throws Exception {
         if (referenceConfig == null) {
-            referenceBeanManager.initReferenceBean(this);
-            applicationContext
-                    .getBean(DubboConfigApplicationListener.class.getName(), DubboConfigApplicationListener.class)
-                    .init();
-            logger.warn(
-                    CONFIG_DUBBO_BEAN_INITIALIZER,
-                    "",
-                    "",
-                    "ReferenceBean is not ready yet, please make sure to call reference interface method after dubbo is started.");
+            synchronized (LockUtils.getSingletonMutex(applicationContext)) {
+                if (referenceConfig == null) {
+                    referenceBeanManager.initReferenceBean(this);
+                    applicationContext
+                            .getBean(
+                                    DubboConfigApplicationListener.class.getName(),
+                                    DubboConfigApplicationListener.class)
+                            .init();
+                    logger.warn(
+                            CONFIG_DUBBO_BEAN_INITIALIZER,
+                            "",
+                            "",
+                            "ReferenceBean is not ready yet, please make sure to "
+                                    + "call reference interface method after dubbo is started.");
+                }
+            }
         }
         // get reference proxy
         // Subclasses should synchronize on the given Object if they perform any sort of extended singleton creation
diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboConfigApplicationListener.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboConfigApplicationListener.java
index fa9d5b2b0b..499e81d679 100644
--- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboConfigApplicationListener.java
+++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboConfigApplicationListener.java
@@ -60,7 +60,7 @@ public class DubboConfigApplicationListener
         }
     }
 
-    public void init() {
+    public synchronized void init() {
         // It's expected to be notified at
         // org.springframework.context.support.AbstractApplicationContext.registerListeners(),
         // before loading non-lazy singleton beans. At this moment, all BeanFactoryPostProcessor have been processed,