Skip to content

Commit

Permalink
Revise shutdown phase log message and executor shutdown documentation
Browse files Browse the repository at this point in the history
Closes gh-32109
  • Loading branch information
jhoeller committed Jan 29, 2024
1 parent a738e4d commit 08e6df8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -490,9 +490,9 @@ else if (member.bean instanceof SmartLifecycle) {
try {
latch.await(this.timeout, TimeUnit.MILLISECONDS);
if (latch.getCount() > 0 && !countDownBeanNames.isEmpty() && logger.isInfoEnabled()) {
logger.info("Failed to shut down " + countDownBeanNames.size() + " bean" +
(countDownBeanNames.size() > 1 ? "s" : "") + " with phase value " +
this.phase + " within timeout of " + this.timeout + "ms: " + countDownBeanNames);
logger.info("Shutdown phase " + this.phase + " ends with " + countDownBeanNames.size() +
" bean" + (countDownBeanNames.size() > 1 ? "s" : "") +
" still running after timeout of " + this.timeout + "ms: " + countDownBeanNames);
}
}
catch (InterruptedException ex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -91,7 +91,7 @@ public abstract class ExecutorConfigurationSupport extends CustomizableThreadFac

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

/**
* Set the RejectedExecutionHandler to use for the ExecutorService.
* Default is the ExecutorService's default abort policy.
* The default is the ExecutorService's default abort policy.
* @see java.util.concurrent.ThreadPoolExecutor.AbortPolicy
*/
public void setRejectedExecutionHandler(@Nullable RejectedExecutionHandler rejectedExecutionHandler) {
Expand All @@ -126,19 +126,25 @@ public void setRejectedExecutionHandler(@Nullable RejectedExecutionHandler rejec
/**
* Set whether to accept further tasks after the application context close phase
* has begun.
* <p>Default is {@code false} as of 6.1, triggering an early soft shutdown of
* <p>The default is {@code false} as of 6.1, triggering an early soft shutdown of
* the executor and therefore rejecting any further task submissions. Switch this
* to {@code true} in order to let other components submit tasks even during their
* own stop and destruction callbacks, at the expense of a longer shutdown phase.
* The executor will not go through a coordinated lifecycle stop phase then
* but rather only stop tasks on its own shutdown. This usually goes along with
* {@link #setWaitForTasksToCompleteOnShutdown "waitForTasksToCompleteOnShutdown"}.
* but rather only stop tasks on its own shutdown.
* <p>{@code acceptTasksAfterContextClose=true} like behavior also follows from
* {@link #setWaitForTasksToCompleteOnShutdown "waitForTasksToCompleteOnShutdown"}
* which effectively is a specific variant of this flag, replacing the early soft
* shutdown in the concurrent managed stop phase with a serial soft shutdown in
* the executor's destruction step, with individual awaiting according to the
* {@link #setAwaitTerminationSeconds "awaitTerminationSeconds"} property.
* <p>This flag will only have effect when the executor is running in a Spring
* application context and able to receive the {@link ContextClosedEvent}.
* @since 6.1
* @see org.springframework.context.ConfigurableApplicationContext#close()
* @see DisposableBean#destroy()
* @see #shutdown()
* @see #setAwaitTerminationSeconds
*/
public void setAcceptTasksAfterContextClose(boolean acceptTasksAfterContextClose) {
this.acceptTasksAfterContextClose = acceptTasksAfterContextClose;
Expand All @@ -147,8 +153,8 @@ public void setAcceptTasksAfterContextClose(boolean acceptTasksAfterContextClose
/**
* Set whether to wait for scheduled tasks to complete on shutdown,
* not interrupting running tasks and executing all tasks in the queue.
* <p>Default is {@code false}, with a coordinated lifecycle stop first (unless
* {@link #setAcceptTasksAfterContextClose "acceptTasksAfterContextClose"}
* <p>The default is {@code false}, with a coordinated lifecycle stop first
* (unless {@link #setAcceptTasksAfterContextClose "acceptTasksAfterContextClose"}
* has been set) and then an immediate shutdown through interrupting ongoing
* tasks and clearing the queue. Switch this flag to {@code true} if you
* prefer fully completed tasks at the expense of a longer shutdown phase.
Expand All @@ -162,6 +168,8 @@ public void setAcceptTasksAfterContextClose(boolean acceptTasksAfterContextClose
* property instead of or in addition to this property.
* @see java.util.concurrent.ExecutorService#shutdown()
* @see java.util.concurrent.ExecutorService#shutdownNow()
* @see #shutdown()
* @see #setAwaitTerminationSeconds
*/
public void setWaitForTasksToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown) {
this.waitForTasksToCompleteOnShutdown = waitForJobsToCompleteOnShutdown;
Expand Down Expand Up @@ -326,7 +334,7 @@ public void shutdown() {
}

/**
* Cancel the given remaining task which never commended execution,
* Cancel the given remaining task which never commenced execution,
* as returned from {@link ExecutorService#shutdownNow()}.
* @param task the task to cancel (typically a {@link RunnableFuture})
* @since 5.0.5
Expand Down

0 comments on commit 08e6df8

Please sign in to comment.