Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk3 min

How Spring Boot Shuts Down: Hooks, Request Draining, and Kubernetes

Spring Boot closes its context through a JVM shutdown hook. Learn how web requests drain, which timeout settings matter, and how Kubernetes termination limits fit in.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When a Spring Boot process exits normally, Spring’s JVM shutdown hook closes the application context, runs lifecycle cleanup, and—on supported embedded web servers—stops new web work while giving in-flight requests a configured window to finish. That application-level window is separate from the time an orchestrator allows the container to terminate.

What starts Spring Boot shutdown?

Each SpringApplication registers a JVM shutdown hook. On an orderly JVM exit, the hook closes the Spring ApplicationContext; context closure then initiates Spring’s lifecycle stop and cleanup processing. Standard callbacks such as DisposableBean and @PreDestroy can release application resources. Spring Boot Reference: SpringApplication

As an Amazon Associate I earn from qualifying purchases.

A process that is forcibly killed does not get the same ordinary cleanup opportunity. In particular, a forced termination such as SIGKILL cannot be handled by the shutdown hook. Spring’s graceful-shutdown guidance also warns that an IDE may stop an application immediately if it does not send a proper SIGTERM. Spring Boot Reference: Graceful Shutdown

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What happens when the application context closes?

Spring Boot performs embedded web-server graceful shutdown in the earliest phase of stopping SmartLifecycle beans. The server stops admitting new work, while active requests get a timeout window to complete before later lifecycle shutdown proceeds. The timeout is configured per shutdown phase with spring.lifecycle.timeout-per-shutdown-phase; the reference uses 20s as an example of the property’s duration syntax, not as a universal recommendation. Spring Boot Reference: Graceful Shutdown

This web-server behavior does not automatically drain every background activity in an application. Message consumers, scheduled jobs, executors, and other application-specific components need their own lifecycle handling and suitable timeouts. If work lasts longer than the configured window or the process’s overall termination deadline, it can still be interrupted.

What do clients see while requests drain?

During graceful shutdown, new requests are not meant to begin processing, while requests already in progress are allowed time to finish. The exact network behavior is server-dependent; persistent connections can also affect when a server considers new work to have arrived. Spring’s current reference describes Jetty, Reactor Netty, and Tomcat and does not promise one universal HTTP status or wire-level response. Spring Boot Reference: Graceful Shutdown

Server differences documented for Spring Boot 3.3.13

The Spring Boot 3.3.13 reference distinguishes Undertow from Jetty, Reactor Netty, and Tomcat: Undertow can accept new connections and respond with HTTP 503, while the other three stop accepting requests at the network layer. This is a version-specific description in the 3.3.13 documentation, not a performance comparison or a guarantee for every release and connection pattern. Spring Boot 3.3.13 Reference: Graceful Shutdown

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Which shutdown settings should you configure?

The current Spring Boot reference says graceful shutdown is enabled by default for its listed embedded servers—Jetty, Reactor Netty, and Tomcat—and for reactive and servlet-based web applications. Set the phase timeout to match the time your application needs to finish in-flight work and perform cleanup. To disable graceful shutdown, the current reference documents server.shutdown=immediate. Spring Boot Reference: Graceful Shutdown

The Spring Boot 3.3.13 page shows explicit configuration with server.shutdown=graceful and a spring.lifecycle.timeout-per-shutdown-phase=20s example. Treat those as examples from that version’s documentation; choose a timeout based on your application’s work and deployment deadline, rather than copying the example as a default. Spring Boot 3.3.13 Reference: Graceful Shutdown

How does Kubernetes change the shutdown sequence?

Spring’s Kubernetes deployment guidance notes that shutdown-related systems act concurrently: Kubernetes begins terminating the pod while service routing changes are also propagating. That can leave a window in which traffic still reaches the pod. A preStop hook can introduce a delay for routing changes to take effect; Kubernetes then sends SIGTERM to the container. Spring Boot Reference: Kubernetes deployment

The same guidance identifies 30 seconds as Kubernetes’ default terminationGracePeriodSeconds. This is a Kubernetes operational default, not a Spring Boot timeout. If the application needs more time, increase the pod’s termination grace period. After the grace period expires, Kubernetes sends SIGKILL to a container that is still running. Coordinate the Spring lifecycle timeout with this overall budget, leaving time for routing, pre-stop behavior, and other cleanup; the Spring timeout alone cannot guarantee a graceful pod termination. Spring Boot Reference: Kubernetes deployment

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How is the process exit code determined?

Cleanup and exit status are separate concerns. Spring’s lifecycle callbacks handle resource cleanup; an ExitCodeGenerator can provide the status code used by SpringApplication.exit. Setting an exit code does not replace the shutdown lifecycle or extend the time available to drain requests. Spring Boot Reference: SpringApplication

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.