Skip to content

Commit 08e6df8

Browse files
committed
Revise shutdown phase log message and executor shutdown documentation
Closes gh-32109
1 parent a738e4d commit 08e6df8

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -490,9 +490,9 @@ else if (member.bean instanceof SmartLifecycle) {
490490
try {
491491
latch.await(this.timeout, TimeUnit.MILLISECONDS);
492492
if (latch.getCount() > 0 && !countDownBeanNames.isEmpty() && logger.isInfoEnabled()) {
493-
logger.info("Failed to shut down " + countDownBeanNames.size() + " bean" +
494-
(countDownBeanNames.size() > 1 ? "s" : "") + " with phase value " +
495-
this.phase + " within timeout of " + this.timeout + "ms: " + countDownBeanNames);
493+
logger.info("Shutdown phase " + this.phase + " ends with " + countDownBeanNames.size() +
494+
" bean" + (countDownBeanNames.size() > 1 ? "s" : "") +
495+
" still running after timeout of " + this.timeout + "ms: " + countDownBeanNames);
496496
}
497497
}
498498
catch (InterruptedException ex) {

spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -91,7 +91,7 @@ public abstract class ExecutorConfigurationSupport extends CustomizableThreadFac
9191

9292
/**
9393
* Set the ThreadFactory to use for the ExecutorService's thread pool.
94-
* Default is the underlying ExecutorService's default thread factory.
94+
* THe default is the underlying ExecutorService's default thread factory.
9595
* <p>In a Jakarta EE or other managed environment with JSR-236 support,
9696
* consider specifying a JNDI-located ManagedThreadFactory: by default,
9797
* to be found at "java:comp/DefaultManagedThreadFactory".
@@ -115,7 +115,7 @@ public void setThreadNamePrefix(@Nullable String threadNamePrefix) {
115115

116116
/**
117117
* Set the RejectedExecutionHandler to use for the ExecutorService.
118-
* Default is the ExecutorService's default abort policy.
118+
* The default is the ExecutorService's default abort policy.
119119
* @see java.util.concurrent.ThreadPoolExecutor.AbortPolicy
120120
*/
121121
public void setRejectedExecutionHandler(@Nullable RejectedExecutionHandler rejectedExecutionHandler) {
@@ -126,19 +126,25 @@ public void setRejectedExecutionHandler(@Nullable RejectedExecutionHandler rejec
126126
/**
127127
* Set whether to accept further tasks after the application context close phase
128128
* has begun.
129-
* <p>Default is {@code false} as of 6.1, triggering an early soft shutdown of
129+
* <p>The default is {@code false} as of 6.1, triggering an early soft shutdown of
130130
* the executor and therefore rejecting any further task submissions. Switch this
131131
* to {@code true} in order to let other components submit tasks even during their
132132
* own stop and destruction callbacks, at the expense of a longer shutdown phase.
133133
* The executor will not go through a coordinated lifecycle stop phase then
134-
* but rather only stop tasks on its own shutdown. This usually goes along with
135-
* {@link #setWaitForTasksToCompleteOnShutdown "waitForTasksToCompleteOnShutdown"}.
134+
* but rather only stop tasks on its own shutdown.
135+
* <p>{@code acceptTasksAfterContextClose=true} like behavior also follows from
136+
* {@link #setWaitForTasksToCompleteOnShutdown "waitForTasksToCompleteOnShutdown"}
137+
* which effectively is a specific variant of this flag, replacing the early soft
138+
* shutdown in the concurrent managed stop phase with a serial soft shutdown in
139+
* the executor's destruction step, with individual awaiting according to the
140+
* {@link #setAwaitTerminationSeconds "awaitTerminationSeconds"} property.
136141
* <p>This flag will only have effect when the executor is running in a Spring
137142
* application context and able to receive the {@link ContextClosedEvent}.
138143
* @since 6.1
139144
* @see org.springframework.context.ConfigurableApplicationContext#close()
140145
* @see DisposableBean#destroy()
141146
* @see #shutdown()
147+
* @see #setAwaitTerminationSeconds
142148
*/
143149
public void setAcceptTasksAfterContextClose(boolean acceptTasksAfterContextClose) {
144150
this.acceptTasksAfterContextClose = acceptTasksAfterContextClose;
@@ -147,8 +153,8 @@ public void setAcceptTasksAfterContextClose(boolean acceptTasksAfterContextClose
147153
/**
148154
* Set whether to wait for scheduled tasks to complete on shutdown,
149155
* not interrupting running tasks and executing all tasks in the queue.
150-
* <p>Default is {@code false}, with a coordinated lifecycle stop first (unless
151-
* {@link #setAcceptTasksAfterContextClose "acceptTasksAfterContextClose"}
156+
* <p>The default is {@code false}, with a coordinated lifecycle stop first
157+
* (unless {@link #setAcceptTasksAfterContextClose "acceptTasksAfterContextClose"}
152158
* has been set) and then an immediate shutdown through interrupting ongoing
153159
* tasks and clearing the queue. Switch this flag to {@code true} if you
154160
* prefer fully completed tasks at the expense of a longer shutdown phase.
@@ -162,6 +168,8 @@ public void setAcceptTasksAfterContextClose(boolean acceptTasksAfterContextClose
162168
* property instead of or in addition to this property.
163169
* @see java.util.concurrent.ExecutorService#shutdown()
164170
* @see java.util.concurrent.ExecutorService#shutdownNow()
171+
* @see #shutdown()
172+
* @see #setAwaitTerminationSeconds
165173
*/
166174
public void setWaitForTasksToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown) {
167175
this.waitForTasksToCompleteOnShutdown = waitForJobsToCompleteOnShutdown;
@@ -326,7 +334,7 @@ public void shutdown() {
326334
}
327335

328336
/**
329-
* Cancel the given remaining task which never commended execution,
337+
* Cancel the given remaining task which never commenced execution,
330338
* as returned from {@link ExecutorService#shutdownNow()}.
331339
* @param task the task to cancel (typically a {@link RunnableFuture})
332340
* @since 5.0.5

0 commit comments

Comments
 (0)