Currently, GrcefulShutdown is geared towards web servers. One another aspect to consider for graceful shutdown is task schedulers and executors. While graceful shutdown is in progress, task schedulers/executors need to reject new tasks.

We put such task scheduler/executor(ExecutorConfigurationSupport beans) handling logic as part of our graceful shutdown.

With new ReadinessStateChangedEvent, it is easy to add such custom handling logic. For example, a ApplicationListener that shutdowns scheduler/executor beans. It may be nice to have such support out of the box from spring-boot since tasks are also common requirement for graceful shutdown.

Comment From: wilkinsona

While graceful shutdown is in progress, task schedulers/executors need to reject new tasks.

I thought about this when implementing graceful shutdown and I don't think it's true for all applications. For example, a request may be in-flight when graceful shutdown begins and successful handling of this request may require the use of an executor. Ideally, the request should be allowed to complete normally so the executor should not be shut down until there are no in-flight requests. On the other hand, there may be an executor that is not involved in HTTP request handling so it could be shutdown as soon as graceful shutdown begins. Only an application developer can know which category things fall into so I think we need to leave it to them to make the decision.

Note that from an external perspective, graceful shutdown is just a SIGTERM and then waiting until the process exits. Once graceful shutdown of the web server has completed, closure of the application context will then proceed as normal. All of Spring Framework's support for smart lifecycle phases, bean disposal, etc is available to you and can be used to control what happens before the JVM exits.