Skip to content

Commit ea71adb

Browse files
LiZhenNetbeiwei30
authored andcommitted
Graceful shutdown enhancement in Spring (#2901)
1 parent 743da20 commit ea71adb

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ public void run() {
5555
if (logger.isInfoEnabled()) {
5656
logger.info("Run shutdown hook now.");
5757
}
58-
destroyAll();
58+
doDestroy();
5959
}
6060

6161
/**
6262
* Destroy all the resources, including registries and protocols.
6363
*/
64-
public void destroyAll() {
64+
public void doDestroy() {
6565
if (!destroyed.compareAndSet(false, true)) {
6666
return;
6767
}

dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/extension/SpringExtensionFactory.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class SpringExtensionFactory implements ExtensionFactory {
4444

4545
public static void addApplicationContext(ApplicationContext context) {
4646
contexts.add(context);
47+
Runtime.getRuntime().removeShutdownHook(DubboShutdownHook.getDubboShutdownHook());
4748
BeanFactoryUtils.addApplicationListener(context, shutdownHookListener);
4849
}
4950

@@ -105,11 +106,8 @@ private static class ShutdownHookListener implements ApplicationListener {
105106
@Override
106107
public void onApplicationEvent(ApplicationEvent event) {
107108
if (event instanceof ContextClosedEvent) {
108-
// we call it anyway since dubbo shutdown hook make sure its destroyAll() is re-entrant.
109-
// pls. note we should not remove dubbo shutdown hook when spring framework is present, this is because
110-
// its shutdown hook may not be installed.
111109
DubboShutdownHook shutdownHook = DubboShutdownHook.getDubboShutdownHook();
112-
shutdownHook.destroyAll();
110+
shutdownHook.doDestroy();
113111
}
114112
}
115113
}

0 commit comments

Comments
 (0)