Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graceful shutdown enhancement in Spring #2901

Merged
merged 1 commit into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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