Skip to content

Commit

Permalink
Graceful shutdown enhancement in Spring (apache#2901)
Browse files Browse the repository at this point in the history
  • Loading branch information
LiZhenNet authored and khanimteyaz committed Dec 17, 2018
1 parent c1b1c92 commit b24c1d5
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 b24c1d5

Please sign in to comment.