Spring Boot Graceful Shutdown

Add graceful shutdown support to Spring Boot applications.

Лицензия

Лицензия

Категории

Категории

Spring Boot Контейнер Микросервисы
Группа

Группа

com.github.timpeeters
Идентификатор

Идентификатор

spring-boot-graceful-shutdown
Последняя версия

Последняя версия

2.2.2
Дата

Дата

Тип

Тип

jar
Описание

Описание

Spring Boot Graceful Shutdown
Add graceful shutdown support to Spring Boot applications.
Ссылка на сайт

Ссылка на сайт

https://github.com/timpeeters/spring-boot-graceful-shutdown
Система контроля версий

Система контроля версий

https://github.com/timpeeters/spring-boot-graceful-shutdown

Скачать spring-boot-graceful-shutdown

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.timpeeters/spring-boot-graceful-shutdown/ -->
<dependency>
    <groupId>com.github.timpeeters</groupId>
    <artifactId>spring-boot-graceful-shutdown</artifactId>
    <version>2.2.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.timpeeters/spring-boot-graceful-shutdown/
implementation 'com.github.timpeeters:spring-boot-graceful-shutdown:2.2.2'
// https://jarcasting.com/artifacts/com.github.timpeeters/spring-boot-graceful-shutdown/
implementation ("com.github.timpeeters:spring-boot-graceful-shutdown:2.2.2")
'com.github.timpeeters:spring-boot-graceful-shutdown:jar:2.2.2'
<dependency org="com.github.timpeeters" name="spring-boot-graceful-shutdown" rev="2.2.2">
  <artifact name="spring-boot-graceful-shutdown" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.timpeeters', module='spring-boot-graceful-shutdown', version='2.2.2')
)
libraryDependencies += "com.github.timpeeters" % "spring-boot-graceful-shutdown" % "2.2.2"
[com.github.timpeeters/spring-boot-graceful-shutdown "2.2.2"]

Зависимости

compile (9)

Идентификатор библиотеки Тип Версия
org.apache.tomcat.embed : tomcat-embed-core Необязательный jar
org.slf4j : slf4j-api jar
org.springframework : spring-beans jar
org.springframework : spring-context jar
org.springframework : spring-core jar
org.springframework.boot : spring-boot jar
org.springframework.boot : spring-boot-actuator Необязательный jar
org.springframework.boot : spring-boot-autoconfigure jar
org.springframework.boot : spring-boot-configuration-processor Необязательный jar

provided (1)

Идентификатор библиотеки Тип Версия
com.fasterxml.jackson.core : jackson-annotations jar

test (9)

Идентификатор библиотеки Тип Версия
junit : junit jar
org.assertj : assertj-core jar 3.15.0
org.asynchttpclient : async-http-client jar 2.12.1
org.mockito : mockito-core jar
org.springframework : spring-web jar
org.springframework.boot : spring-boot-starter-actuator jar
org.springframework.boot : spring-boot-starter-logging jar
org.springframework.boot : spring-boot-starter-test jar
org.springframework.boot : spring-boot-starter-web jar

Модули Проекта

Данный проект не имеет модулей.

Spring Boot Graceful Shutdown

Dependabot Status Maven Central

This project adds graceful shutdown behavior to Spring Boot.

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 Graceful Shutdown version.

Spring Boot Spring Boot Graceful Shutdown Branch
1.5.x 1.0.x 1.0.x
2.0.x 2.0.x 2.0.x
2.1.x 2.1.x 2.1.x
2.2.x 2.2.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

Currently this project only supports Tomcat as embedded web container for Spring Boot. Undertow and/or Jetty are not yet supported.

Installation

  1. Add the following Maven dependency:
<dependency>
    <groupId>com.github.timpeeters</groupId>
    <artifactId>spring-boot-graceful-shutdown</artifactId>
    <version>X.X.X</version>
</dependency>

Configuration

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

It is important to specify the time unit, otherwise you end up with milliseconds.

Alternative implementations

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

References

Версии библиотеки

Версия
2.2.2
2.2.1
2.2.0
2.1.2
2.1.1
2.1.0
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0