How Spring 7.0.4 Fixes Deadlock Bugs and Boosts Startup Speed by Up to 50%
Spring Framework 7.0.4 resolves a rare deadlock caused by concurrent shutdown paths in Kubernetes, introduces dozens of bug fixes and performance tweaks—including faster request routing, annotation caching, and validation refactoring—that together can cut startup time by 30‑50% depending on the JDK version.
Deadlock in Spring 7.0.0‑7.0.3
When a pod is restarted in Kubernetes, the application may hang because ConfigurableApplicationContext.close() and the JVM ShutdownHook compete for the same lock, causing a classic deadlock. The race occurs during graceful shutdown (SIGTERM) and can be triggered by SIGKILL before the JVM exits. The bug is probabilistic and only appears in container environments.
Fix in Issue #36260
Spring rewrote the ConfigurableApplicationContext shutdown state machine, adding an independent shutdown flag and a CAS operation. The first thread that acquires the lock sets the flag; the other thread detects the flag and backs off, preventing simultaneous execution of close() and the ShutdownHook.
Self‑check: If a Spring 7.x service starts a pod that never finishes, run jstack . If you see threads waiting on close() and ShutdownHook , the bug is present.
Additional bugs fixed in 7.0.4
#36293 – ConcurrentReferenceHashMap lock contention caused silent throughput drops under high concurrency.
#36298 – Header modifications in HandlerInterceptor were not propagated downstream.
#36266 – StompBrokerRelayMessageHandler failed to reconnect after the broker restarted.
#36285 & #36226 – Message converters now accept MIME wildcard */* and HeadersAdapter.remove() returns null instead of an empty list.
Performance optimizations in 7.0.4
1. Request‑mapping routing
Replaced the URL‑pattern hash algorithm with a faster implementation (+5% at million QPS).
Shortened the bean‑lookup path for HandlerMethod by removing redundant reflection objects.
Added a fast‑path for single‑URL @RequestMapping patterns, bypassing generic pattern matching.
Decoupled API‑version mapping to avoid extra checks.
Result: Gateway‑type services see ~15‑20% lower response time; CRUD‑heavy services benefit less because the database becomes the bottleneck.
2. Annotation‑parsing cache
Spring now caches the result of parsing annotations such as @Transactional, @Cacheable, @Validated, and @RequestMapping. The first parse is performed once; subsequent calls read the cached metadata directly.
@MyTransactional // includes @Transactional
@MyCacheable // includes @Cacheable
@MyValidated // includes @Validated
public void doSomething() { ... }3. Validation reflection slimming
Bean Validation no longer repeatedly calls Class.getAnnotations() when determining validation groups, reducing reflection overhead in bulk‑import or multi‑step form scenarios.
Combined effect: Startup time improves 30‑50% (depending on JDK) and request handling speeds up an additional 10‑20%.
JDK version impact
JDK 17 – ~10‑15% startup speedup (routing and annotation cache only; no virtual‑thread benefits).
JDK 21 – ~25‑35% speedup (virtual threads available but scheduler not newest).
JDK 25 – ~40‑50% speedup (full Reactor 2025.0.3 + Spring 7.0 async startup optimizations).
Spring 7.0.4 also upgrades Reactor to 2025.0.3, Micrometer to 1.6.3, ASM to 9.9.1 (JDK 25 bytecode support), and Apache POI to 5.5 (memory optimizations for large Excel exports).
Upgrade decision guidance
Spring 7.x + Kubernetes – Upgrade immediately; deadlock fix and performance gains are critical.
Spring 7.x + traditional deployment – Upgrade in the next iteration; no breaking changes.
Spring Boot 4.0 – Wait for Boot 4.0.4, which bundles Spring 7.0.4.
Spring 6.x / Boot 3.x – Do not rush; migration requires JDK ≥ 17 and full Jakarta namespace migration (javax → jakarta).
Prerequisites for migrating from Spring 6.x to 7.x
JDK ≥ 17 (21+ recommended).
All dependencies must have completed the Jakarta migration (e.g., javax.servlet → jakarta.servlet, javax.persistence → jakarta.persistence).
Read the official migration guide before changing pom files (https://spring.io/projects/spring-boot).
Reference
Full release notes and list of 40+ new features are available at
https://github.com/spring-projects/spring-framework/releases/tag/v7.0.4.
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
