Skip to content

Questions about shutdown graceful #2865

@zonghaishang

Description

@zonghaishang
  • I have searched the issues of this repository and believe that this is not a duplicate.
  • I have checked the FAQ of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 2.7.0
  • Operating System version: mac
  • Java version: 1.8

org.apache.dubbo.config.AbstractConfig:

static {
    // this is only for compatibility
    Runtime.getRuntime().addShutdownHook(DubboShutdownHook.getDubboShutdownHook());
}

The jvm hook is registered by default. When the user uses spring, the default hook is not removed. It was the earliest cause of this shutdown graceful, mainly due to this reason. Please note:
Spring does not register hooks by default, but users may register themselves, spring-boot will also register hooks by default.

org.apache.dubbo.config.spring.extension.SpringExtensionFactory.ShutdownHookListener:

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();
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions