Enhance shutdown hook logs (#12336)

This commit is contained in:
Albumen Kevin 2023-05-17 14:51:15 +08:00 committed by GitHub
parent 35a6365d3f
commit 7b595b19bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 5 deletions

View File

@ -90,7 +90,7 @@ public class DubboShutdownHook extends Thread {
boolean hasModuleBindSpring = false; boolean hasModuleBindSpring = false;
// check if any modules are bound to Spring // check if any modules are bound to Spring
for (ModuleModel module: applicationModel.getModuleModels()) { for (ModuleModel module : applicationModel.getModuleModels()) {
if (module.isLifeCycleManagedExternally()) { if (module.isLifeCycleManagedExternally()) {
hasModuleBindSpring = true; hasModuleBindSpring = true;
break; break;
@ -104,14 +104,14 @@ public class DubboShutdownHook extends Thread {
To avoid shutdown conflicts between Dubbo and Spring, To avoid shutdown conflicts between Dubbo and Spring,
wait for the modules bound to Spring to be handled by Spring until timeout. wait for the modules bound to Spring to be handled by Spring until timeout.
*/ */
logger.info("Waiting for modules managed by Spring to be shutdown."); logger.info("Waiting for modules(" + applicationModel.getDesc() + ") managed by Spring to be shutdown.");
while (!applicationModel.isDestroyed() && hasModuleBindSpring while (!applicationModel.isDestroyed() && hasModuleBindSpring
&& (System.currentTimeMillis() - start) < timeout) { && (System.currentTimeMillis() - start) < timeout) {
try { try {
TimeUnit.MILLISECONDS.sleep(10); TimeUnit.MILLISECONDS.sleep(10);
hasModuleBindSpring = false; hasModuleBindSpring = false;
if (!applicationModel.isDestroyed()) { if (!applicationModel.isDestroyed()) {
for (ModuleModel module: applicationModel.getModuleModels()) { for (ModuleModel module : applicationModel.getModuleModels()) {
if (module.isLifeCycleManagedExternally()) { if (module.isLifeCycleManagedExternally()) {
hasModuleBindSpring = true; hasModuleBindSpring = true;
break; break;
@ -123,11 +123,15 @@ public class DubboShutdownHook extends Thread {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
} }
if (!applicationModel.isDestroyed()) {
long usage = System.currentTimeMillis() - start;
logger.info("Dubbo wait for application(" + applicationModel.getDesc() + ") managed by Spring to be shutdown failed, " +
"time usage: " + usage + "ms");
}
} }
} }
if (!applicationModel.isDestroyed()) { if (!applicationModel.isDestroyed()) {
logger.info("Dubbo shuts down application " + logger.info("Dubbo shutdown hooks execute now. " + applicationModel.getDesc());
"after Spring fails to do in time or doesn't do it completely.");
applicationModel.destroy(); applicationModel.destroy();
} }
} }