Tagged articles
11 articles
Page 1 of 1
JD Tech Talk
JD Tech Talk
Apr 29, 2025 · Backend Development

Understanding Java ShutdownHook: Principles, Implementation, and Use Cases

This article explains the concept of Java's Runtime.addShutdownHook, details its underlying implementation in the Runtime and ApplicationShutdownHooks classes, demonstrates usage with code examples, discusses typical application scenarios, potential risks of long‑running hooks, and provides best‑practice recommendations for safe JVM shutdown handling.

JVMJavaResource Management
0 likes · 7 min read
Understanding Java ShutdownHook: Principles, Implementation, and Use Cases
JD Cloud Developers
JD Cloud Developers
Apr 29, 2025 · Backend Development

How to Safely Use Java Shutdown Hooks to Clean Up Resources on JVM Exit

This article explains the purpose and inner workings of Java's Runtime.addShutdownHook, walks through the Runtime and ApplicationShutdownHooks source code, demonstrates practical usage with examples, discusses common scenarios, potential risks, and best‑practice solutions for reliable resource cleanup during JVM shutdown.

BackendJVMShutdownHook
0 likes · 9 min read
How to Safely Use Java Shutdown Hooks to Clean Up Resources on JVM Exit
FunTester
FunTester
Sep 10, 2023 · Backend Development

Mastering Java ShutdownHook: Clean Up Resources and Track Tasks Gracefully

This article demonstrates practical ways to leverage Java's ShutdownHook API for task statistics, connection cleanup, handling JVM abnormal exits, and persisting state during performance testing, providing code examples, pitfalls of daemon threads, and strategies for reliable resource management in backend applications.

BackendJVMJava
0 likes · 8 min read
Mastering Java ShutdownHook: Clean Up Resources and Track Tasks Gracefully
FunTester
FunTester
Aug 17, 2023 · Backend Development

Understanding java.lang.Runtime.addShutdownHook for JVM Graceful Shutdown

This article explains the Java Runtime addShutdownHook API, its purpose for registering shutdown hooks, typical use cases such as resource cleanup, state saving, and logging, and provides practical Java and Groovy code examples while noting that hook execution order is unspecified.

GroovyJavaRuntime
0 likes · 6 min read
Understanding java.lang.Runtime.addShutdownHook for JVM Graceful Shutdown
Full-Stack Internet Architecture
Full-Stack Internet Architecture
May 8, 2021 · Backend Development

Graceful Shutdown of RocketMQ Consumer in Spring Applications

The article recounts a production incident caused by an ungraceful RocketMQ consumer shutdown, analyzes the root cause involving Spring's bean destruction order and ShutdownHook behavior, and presents two solutions—using the official Spring‑Boot starter with SmartLifecycle or handling ContextClosedEvent—to achieve orderly termination.

BackendGraceful ShutdownRocketMQ
0 likes · 5 min read
Graceful Shutdown of RocketMQ Consumer in Spring Applications
Zhuanzhuan Tech
Zhuanzhuan Tech
Dec 31, 2020 · Operations

How to Implement Graceful Restart of the JVM

This article explains the three JVM shutdown methods, how to use ShutdownHook and custom SignalHandler for cleanup, and outlines a step‑by‑step graceful restart process using kill -12, kill -15, and kill -9 signals, with sample scripts and references.

Graceful ShutdownJVMJava
0 likes · 5 min read
How to Implement Graceful Restart of the JVM
dbaplus Community
dbaplus Community
Aug 23, 2020 · Backend Development

Implementing Graceful Shutdown for Java Microservices with ShutdownHook

This article explains why abrupt service restarts cause "Can not get connection to server" errors in Zookeeper‑based microservices and details a Java ShutdownHook solution that deregisters instances, processes in‑flight requests, and prevents client‑side failures during graceful shutdown.

Backend DevelopmentGraceful ShutdownJava
0 likes · 8 min read
Implementing Graceful Shutdown for Java Microservices with ShutdownHook