Quick revision
The short answer
With server.shutdown=graceful, the embedded server stops accepting new requests when the application is asked to stop and waits for requests already running to finish. spring.lifecycle.timeout-per-shutdown-phase sets the maximum wait, 30 seconds by default, and requests still running after that are cut off. Graceful is the default from Spring Boot 3.4; earlier versions defaulted to immediate.
What to remember
In this answer, we saw that server.shutdown=graceful makes the embedded server stop accepting new requests and wait for active ones before the rest of the application stops. spring.lifecycle.timeout-per-shutdown-phase, 30 seconds by default, caps that wait, and requests still running afterwards are cut off. Graceful is the default from Boot 3.4, earlier versions were immediate, and the timeout must fit inside the platform's own grace period.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
With server.shutdown=graceful, the embedded server stops accepting new requests when the application is asked to stop and waits for requests already running to finish. spring.lifecycle.timeout-per-shutdown-phase sets the maximum wait, 30 seconds by default, and requests still running after that are cut off. Graceful is the default from Spring Boot 3.4; earlier versions defaulted to immediate.
Why this question is asked
Every deploy stops old instances of our service. If an instance stops in the middle of a payment request, the user sees an error even though nothing was wrong with the code. Graceful shutdown is the setting that lets an instance finish its work before it goes, and interviewers ask about it because it is a small property with a large effect on how smooth deploys feel. In this answer, we will recap how a Spring Boot application shuts down, see what graceful shutdown changes step by step, look at the properties that control it, and see what happens to requests that run too long.
1A Quick Recap of Application Shutdown
When the JVM receives a termination signal, such as SIGTERM sent by Kubernetes or by systemd, Spring Boot's shutdown hook closes the application context. Closing the context stops beans in phases: components that implement SmartLifecycle are stopped in reverse order of their phase, then singleton beans are destroyed, which closes things like connection pools.
The embedded web server is one of those lifecycle components. In immediate mode, it simply stops: the listening socket closes and requests in progress are interrupted, so their clients see a reset connection or an incomplete response.
2What server.shutdown=graceful Changes
In graceful mode, stopping the web server becomes a two-part step. First the server stops accepting new requests. Then it waits for the requests that are already running to complete, and only after that does the rest of the context shut down, so those requests can still use the database pool and other beans.
7 messages in order. Play them, or step through them one at a time.
New requests stop first; the database pool stays open until running requests are done.
How the server stops accepting differs a little by server. Tomcat, Jetty and Reactor Netty stop accepting at the network level, so new connections are not taken. Undertow, in Boot 3, accepted them and answered 503 Service Unavailable instead. In every case, in-flight requests are allowed to finish.
We can see it in the log. When shutdown starts, Boot logs that it is commencing graceful shutdown and waiting for active requests to complete, and when they have finished it logs that graceful shutdown is complete (the exact wording can vary by version).
3The Timeout and What Happens After It
Waiting forever would be dangerous: a request stuck on a hung downstream call would block the shutdown indefinitely. So Spring waits at most spring.lifecycle.timeout-per-shutdown-phase for each lifecycle phase, and the default is 30 seconds. The graceful wait for the web server happens inside one of those phases.
If requests are still running when the timeout expires, Spring stops waiting and continues the shutdown. The server is stopped, and those requests are cut off, just as they would be with immediate shutdown. So graceful shutdown protects normal requests, not requests that take longer than the timeout.
Notice that the timeout must fit inside whatever is allowed to stop us from outside. In Kubernetes, the pod's terminationGracePeriodSeconds, also 30 seconds by default, ends with a SIGKILL that no setting inside the JVM can survive. If we raise the Spring timeout to 60 seconds, we must raise the grace period above it too.
4Before and After Boot 3.4
Before Spring Boot 3.4, server.shutdown defaulted to immediate, so every application that did not set the property lost its in-flight requests on each deploy. From Boot 3.4 the default is graceful for all the embedded servers, which is what most services want. When we upgrade an older service, it is worth checking for an explicit server.shutdown=immediate left in old configuration, and for tests that assumed the application stops instantly.
| Setting | Default | Effect |
|---|---|---|
server.shutdown (Boot 3.4+) | graceful | Stop accepting, wait for active requests |
server.shutdown (before 3.4) | immediate | Stop at once, in-flight requests cut off |
spring.lifecycle.timeout-per-shutdown-phase | 30s | Maximum wait per phase, then continue |
Kubernetes terminationGracePeriodSeconds | 30 | SIGKILL after this, must be larger |
5Follow-up questions
Does graceful shutdown also stop scheduled tasks and message listeners gracefully?
Not through server.shutdown, which is about the web server. Listener containers such as Kafka and RabbitMQ are lifecycle components with their own stop behaviour, and task executors have properties such as spring.task.execution.shutdown.await-termination. They all share the per-phase timeout, so we check each kind of background work separately.
Why does graceful shutdown not prevent all errors during a Kubernetes deploy?
Because the load balancer may still send new requests to the pod for a short time after SIGTERM, and a server that has stopped accepting refuses them. That is solved outside the application with a preStop delay, so that endpoints update before the app stops accepting.
How can we test graceful shutdown?
Start the application, send a slow request, send SIGTERM to the process while the request runs, and check that the client still gets its full response and the log shows the graceful shutdown messages. Repeating the test with a request longer than the timeout shows the cut-off case.
6Conclusion
In this answer, we saw that server.shutdown=graceful makes the embedded server stop accepting new requests and wait for active ones before the rest of the application stops. spring.lifecycle.timeout-per-shutdown-phase, 30 seconds by default, caps that wait, and requests still running afterwards are cut off. Graceful is the default from Boot 3.4, earlier versions were immediate, and the timeout must fit inside the platform's own grace period.
Open with
server.shutdown=graceful changes what the embedded server does when the application is asked to stop, for example on SIGTERM during a deploy. Instead of stopping at once and cutting off requests in progress, the server first stops accepting new requests and then waits for the active ones to complete.
Then, if they want more
Only after that does Spring stop the remaining beans and close things like the connection pool, so the running requests can still finish their work. The wait is capped by spring.lifecycle.timeout-per-shutdown-phase, which is 30 seconds by default, because shutdown happens in lifecycle phases and each phase gets at most that long.
If a request is still running after the timeout, Spring gives up waiting and continues, so that request is cut off just as with immediate shutdown. Since Spring Boot 3.4, graceful is the default for the embedded servers; before 3.4 the default was immediate, so older services had to set it explicitly.
One thing I always check is the outer limit: in Kubernetes, terminationGracePeriodSeconds is also 30 by default and ends with SIGKILL, so if I raise the Spring timeout I raise the grace period above it as well.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Boot 3.4
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Boot reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What does server.shutdown=graceful do and which properties control it?": https://scrivio-interview-library.netlify.app/spring-boot/embedded-servers/b769ad7ec1/