During rolling deployments and application restarts, running XXL-JOB tasks can be interrupted mid-execution, causing incomplete business data and scheduling failures. Microservices Engine (MSE) XXL-JOB provides built-in graceful shutdown through the SchedulerX plug-in: it drains traffic from an executor, waits for running jobs to finish, and then stops the process. No modifications to the open-source XXL-JOB server code are required.
How it works
When graceful shutdown is enabled, MSE XXL-JOB follows this sequence before stopping an executor:
Deregister the executor -- The executor sends a
registryRemoverequest to the MSE XXL-JOB server and immediately removes itself from the active executor list. The server updatesaddress_listin thexxl_job_grouptable in real time, so no new jobs are dispatched to this node.Wait for running jobs -- Depending on the shutdown mode, the executor waits for all running jobs (and optionally queued jobs in the
JobThreadqueue) to complete.Report execution results -- The
TriggerCallbackThreadflushes all pending execution results back to the server.Stop the process -- The JVM shutdown hook completes and the application process exits.
Why open-source XXL-JOB needs enhancement
Prerequisites
Before you begin, make sure that you have:
MSE XXL-JOB engine version 2.1.0 or later. See Release notes for XXL-JOB
The SchedulerX plug-in dependency added to your project. See Release notes for the XXL-JOB plug-in
Add the following dependency to your pom.xml:
<dependency>
<groupId>com.aliyun.schedulerx</groupId>
<artifactId>schedulerx3-plugin-xxljob</artifactId>
<version>Latest version</version>
</dependency>Integrate the plug-in with your executor
Choose the integration method that matches your application framework.
Spring Boot (recommended)
The plug-in registers graceful shutdown automatically through Spring Boot auto-configuration. No additional code is needed.
Add the shutdown mode to your application.properties:
xxl.job.executor.shutdownMode=WAIT_ALLOr in application.yml:
xxl:
job:
executor:
shutdownMode: WAIT_ALLSpring (non-Boot)
For Spring web applications, add the Maven dependency and application.properties configuration from the Spring Boot section above, then register the plug-in initializer in your web.xml:
<web-app>
<context-param>
<param-name>globalInitializerClasses</param-name>
<param-value>com.aliyun.schedulerx.xxljob.enhance.XxlJobExecutorEnhancerInitializer</param-value>
</context-param>
</web-app>No framework (plain Java)
For applications that start executors without a framework, load the plug-in enhancements manually and register a JVM shutdown hook.
Make sure xxl-job-executor.properties includes the shutdown mode:
xxl.job.executor.shutdownMode=WAIT_ALLStop the application gracefully
The shutdown mode only takes effect when the JVM receives a SIGTERM signal (equivalent to kill -15). Choose the method that matches your deployment environment.
If your Spring Boot application has Spring Boot Actuator enabled, you can also trigger graceful shutdown through the /actuator/shutdown endpoint.
Self-managed CD pipeline
Create a stop.sh script that sends SIGTERM, waits for the application to exit, and falls back to SIGKILL on timeout:
Kubernetes
Kubernetes sends SIGTERM to PID 1 in the container by default, which triggers the JVM shutdown hook automatically.
If the application is not PID 1 (for example, in a multi-process container), configure a preStop hook to send the signal explicitly:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
# Default: 30. Set this to a value longer than the maximum expected job execution time.
terminationGracePeriodSeconds: 30
containers:
- name: my-app-container
image: my-app-image:latest
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "kill -15 <app-pid> && sleep 30"]Set terminationGracePeriodSeconds to a value longer than the maximum expected job execution time. If the grace period expires before jobs finish, Kubernetes sends SIGKILL and force-terminates the pod, which defeats graceful shutdown. The default value is 30 seconds.
Alibaba Cloud application release platform
Automatic graceful shutdown integration for the Alibaba Cloud application release platform will be available soon.
Shutdown mode reference
| Mode | Behavior | When to use |
|---|---|---|
WAIT_ALL (recommended) | Waits for all running jobs and queued jobs to complete before exiting. | Most production workloads. No job is lost. |
WAIT_RUNNING | Waits for currently running jobs to complete. Queued jobs are dropped. | Latency-sensitive deployments where fast restarts take priority over queued jobs. |
| Not configured | Uses the default open-source XXL-JOB behavior. Running jobs are interrupted and queued jobs are discarded. | Not recommended for production. |
Configure the shutdown mode in your application properties:
# Graceful shutdown mode. Valid values: WAIT_ALL, WAIT_RUNNING.
# If not configured, the default open-source XXL-JOB behavior applies (no graceful shutdown).
xxl.job.executor.shutdownMode=WAIT_ALLOr in application.yml:
xxl:
job:
executor:
# Graceful shutdown mode. Valid values: WAIT_ALL, WAIT_RUNNING.
shutdownMode: WAIT_ALL


