Skip to content

Commit

Permalink
Graceful shutdown enhancement in Spring (#2901)
Browse files Browse the repository at this point in the history
  • Loading branch information
LiZhenNet authored and beiwei30 committed Dec 7, 2018
1 parent 743da20 commit ea71adb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public void run() {
if (logger.isInfoEnabled()) {
logger.info("Run shutdown hook now.");
}
destroyAll();
doDestroy();
}

/**
* Destroy all the resources, including registries and protocols.
*/
public void destroyAll() {
public void doDestroy() {
if (!destroyed.compareAndSet(false, true)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class SpringExtensionFactory implements ExtensionFactory {

public static void addApplicationContext(ApplicationContext context) {
contexts.add(context);
Runtime.getRuntime().removeShutdownHook(DubboShutdownHook.getDubboShutdownHook());
BeanFactoryUtils.addApplicationListener(context, shutdownHookListener);
}

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

0 comments on commit ea71adb

Please sign in to comment.