kylixs commented on a change in pull request #9015:
URL: https://github.com/apache/dubbo/pull/9015#discussion_r734239467



##########
File path: 
dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java
##########
@@ -554,63 +556,70 @@ private boolean hasPendingModule() {
         return found;
     }
 
-    private CompletableFuture getStartFuture() {
-        if (startFuture == null) {
-            synchronized (this) {
-                if (startFuture == null) {
-                    startFuture = new CompletableFuture();
-                }
-            }
-        }
-        return startFuture;
-    }
-
-
+    @SuppressWarnings("rawtypes")
     private void doStart() {
-        startModules();
+        List<Future> futures = startModules();
 
         // prepare application instance
         prepareApplicationInstance();
 
+        // keep starting modules while state is starting
         executorRepository.getSharedExecutor().submit(() -> {
-            while (true) {
-                // notify on each module started
-                synchronized (startedLock) {
-                    try {
-                        startedLock.wait(500);
-                    } catch (InterruptedException e) {
-                        // ignore
-                    }
-                }
-
-                // if has new module, do start again
-                if (hasPendingModule()) {
-                    startModules();
-                    continue;
-                }
-
-                DeployState newState = checkState();
-                if (!(newState == DeployState.STARTING || newState == 
DeployState.PENDING)) {
-                    // start finished or error
-                    break;
-                }
-            }
+            awaitDeployFinished(futures);
         });
     }
 
-    private void startModules() {
+    @SuppressWarnings("rawtypes")
+    private List<Future> startModules() {
         // copy current modules, ignore new module during starting
         List<ModuleModel> moduleModels = new 
ArrayList<>(applicationModel.getModuleModels());
+        List<Future> futures = new ArrayList<>(moduleModels.size());
         for (ModuleModel moduleModel : moduleModels) {
             // export services in module
             if (moduleModel.getDeployer().isPending()) {
-                moduleModel.getDeployer().start();
+                futures.add(moduleModel.getDeployer().start());
+            }
+        }
+        return futures;
+    }
+
+    /**
+     * keep starting modules while state is starting. 
+     * 
+     * @param futures
+     */
+    @SuppressWarnings("rawtypes")
+    private void awaitDeployFinished(List<Future> futures) {
+        while (isStarting()) {
+            if (futures.isEmpty()) {
+                try {
+                    Thread.sleep(DEFAULT_TIMEOUT);

Review comment:
       Monitoring the `startedLock` is to process the module started event in 
time. And after modifying it to monitor the future, it may be processed delayed.
   




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to