Operations 10 min read

Graceful Shutdown and Deployment Practices for SpringBoot Microservices

This article explains how to implement graceful shutdown and startup for SpringBoot microservices using Dubbo, including unregistering services, timed waits, kill signals, JVM tuning, health checks, and deployment strategies such as rolling and blue‑green releases.

IT Services Circle
IT Services Circle
IT Services Circle
Graceful Shutdown and Deployment Practices for SpringBoot Microservices

The author introduces the proper way to bring services offline and online, emphasizing that while the process seems simple—stop the application and restart it—there are many hidden details that need to be handled automatically.

Graceful shutdown starts by unregistering the provider from the service registry (Zookeeper or Nacos) so consumers stop sending new requests. Because in‑flight requests may still be processing, the script then sleeps for about 10 seconds to allow them to finish before terminating the JVM with a kill -15 signal. After the kill, the script checks the process every second for up to 10 seconds; if the process is still alive, it falls back to kill -9 . This two‑stage approach works around shortcomings in Dubbo 2.5.x/2.6.x graceful shutdown implementations.

The shutdown flow is illustrated in the following diagram:

Startup for a SpringBoot application can start with a simple java -jar <jar_path> --spring.config.location=xxx --spring.pid.file=xxx , but in production environments this is insufficient. The article provides a comprehensive set of JVM parameters for high‑traffic services, including heap size, GC options, Metaspace settings, and the -Djava.security.egd=file:/dev/./urandom flag to speed up SecureRandom generation.

java -jar jar包路径 --spring.config.location=xxx --spring.pid.file=xxx -server -Xmx5g -Xms5g -Xmn2g -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m -Xss256k -XX:SurvivorRatio=8 \
-XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=70 \
-XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${APPLICATION_LOG_DIR} -Djava.security.egd=file:/dev/./urandom -javaagent:$SW_AGENT_JAR -Dskywalking_config=$SW_AGENT_CONFIG

Monitoring is achieved by installing the SkyWalking agent as a Java agent ( -javaagent:$SW_AGENT_JAR -Dskywalking_config=$SW_AGENT_CONFIG ) to collect metrics and visualize them.

A health‑check endpoint is recommended to verify that the service is truly up. An example Spring service implementation is shown below:

@Service(protocol = {"rest"})
public class HealthCheckServiceImpl implements HealthCheckService {
    @Resource
    private TestDAO testDAO;

    @Override
    public String getHealthStatus() {
        List
testDOS = TestDAO.getResult(123);
        Assert.isTrue(testDOS != null, "dao 有问题 null");
        // redis 检测
        // 此处省略其它检测
        return "health";
    }
}

After the service starts, a script can curl http://ip:port/service/health/deepCheck ; a response of "health" confirms successful deployment.

Release strategies covered include rolling deployment—updating a few servers at a time until the whole cluster runs the new version—and blue‑green deployment, where a parallel environment is prepared and traffic is switched via Dubbo routing. The article includes diagrams for both approaches.

In summary, the key points are:

Ensure graceful shutdown by unregistering services, waiting for in‑flight requests, and using a staged kill process.

Perform thorough JVM tuning, health checks, and monitoring before bringing a new version online.

CI/CDDeploymentDubboSpringBootGraceful Shutdownblue-greenRolling Release
IT Services Circle
Written by

IT Services Circle

Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.