Skip to content
No description, website, or topics provided.
Java
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src change Variable name Sep 14, 2019
.gitignore init Sep 11, 2019
LICENSE init Sep 11, 2019
README.md "spring-boot-starter-actuator" with additional text Sep 16, 2019
mvnw init Sep 11, 2019
mvnw.cmd
pom.xml "spring-boot-starter-actuator" with additional text Sep 16, 2019

README.md

Spring Boot Graceful Shutdown

Maven Central

This project adds graceful shutdown behavior to Spring Boot.

The project referred to "https://github.com/timpeeters/spring-boot-graceful-shutdown" and tried to improve it further.

Versions

Multiple branches are maintained to support multiple Spring Boot versions. The following tables show the relation between the Spring Boot version and the Spring Boot Actuator Server Config version.

Spring Boot Spring Boot Actuator Server Config Branch
2.1.x 2.1.x master

Flow

  1. The JVM receives the SIGTERM signal and starts shutting down the Spring container.
  2. A Spring EventListener listens for a ContextClosedEvent and is invoked once the shutdown is started.
  3. The EventListener updates a Spring Boot HealthIndicator and puts it "out of service".
  4. The context shutdown is delayed using a Thread.sleep to allow the load balancer to see the updated HealthIndicator status and stop forwarding requests to this instance.
  5. When the Thread.sleep is finished, the Tomcat container is gracefully shutdown. First by pausing the connector, no longer accepting new request. Next, by allowing the Tomcat thread pool a configurable amount of time to finish the active threads.
  6. Finally, the Spring context is closed.

Limitations

  1. Currently this project only supports Tomcat as embedded web container for Spring Boot. ( Undertow and/or Jetty are not yet supported. )
  2. org.springframework.boot:spring-boot-starter-actuator is required

Installation

for Maven:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
    <version>X.X.X.RELEASE</version>
</dependency>
<dependency>
    <groupId>me.silvernine</groupId>
    <artifactId>spring-graceful-shutdown</artifactId>
    <version>X.X.X</version>
</dependency>

for Gradle:

compile 'org.springframework.boot:spring-boot-starter-actuator:X.X.X.RELEASE'
compile 'me.silvernine:spring-boot-graceful-shutdown:X.X.X'

Configuration

Key Default value Description
graceful.shutdown.enabled false Indicates whether graceful shutdown is enabled or not.
graceful.shutdown.timeout 60s The number of seconds to wait for active threads to finish before shutting down the Tomcat connector.
graceful.shutdown.wait 30s The number of seconds to return "out of service" on the health page before starting the graceful shutdown.

Alternative implementations

We found several alternatives for graceful shutdown behavior in Spring Boot.

References

You can’t perform that action at this time.