Revise shutdown phase log message and executor shutdown documentation

Closes gh-32109
This commit is contained in:
Juergen Hoeller 2024-01-29 13:03:20 +01:00
parent a738e4d5fd
commit 08e6df8832
2 changed files with 21 additions and 13 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -490,9 +490,9 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
try { try {
latch.await(this.timeout, TimeUnit.MILLISECONDS); latch.await(this.timeout, TimeUnit.MILLISECONDS);
if (latch.getCount() > 0 && !countDownBeanNames.isEmpty() && logger.isInfoEnabled()) { if (latch.getCount() > 0 && !countDownBeanNames.isEmpty() && logger.isInfoEnabled()) {
logger.info("Failed to shut down " + countDownBeanNames.size() + " bean" + logger.info("Shutdown phase " + this.phase + " ends with " + countDownBeanNames.size() +
(countDownBeanNames.size() > 1 ? "s" : "") + " with phase value " + " bean" + (countDownBeanNames.size() > 1 ? "s" : "") +
this.phase + " within timeout of " + this.timeout + "ms: " + countDownBeanNames); " still running after timeout of " + this.timeout + "ms: " + countDownBeanNames);
} }
} }
catch (InterruptedException ex) { catch (InterruptedException ex) {

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -91,7 +91,7 @@ public abstract class ExecutorConfigurationSupport extends CustomizableThreadFac
/** /**
* Set the ThreadFactory to use for the ExecutorService's thread pool. * 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, * <p>In a Jakarta EE or other managed environment with JSR-236 support,
* consider specifying a JNDI-located ManagedThreadFactory: by default, * consider specifying a JNDI-located ManagedThreadFactory: by default,
* to be found at "java:comp/DefaultManagedThreadFactory". * to be found at "java:comp/DefaultManagedThreadFactory".
@ -115,7 +115,7 @@ public abstract class ExecutorConfigurationSupport extends CustomizableThreadFac
/** /**
* Set the RejectedExecutionHandler to use for the ExecutorService. * 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 * @see java.util.concurrent.ThreadPoolExecutor.AbortPolicy
*/ */
public void setRejectedExecutionHandler(@Nullable RejectedExecutionHandler rejectedExecutionHandler) { public void setRejectedExecutionHandler(@Nullable RejectedExecutionHandler rejectedExecutionHandler) {
@ -126,19 +126,25 @@ public abstract class ExecutorConfigurationSupport extends CustomizableThreadFac
/** /**
* Set whether to accept further tasks after the application context close phase * Set whether to accept further tasks after the application context close phase
* has begun. * 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 * 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 * 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. * 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 * 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 * but rather only stop tasks on its own shutdown.
* {@link #setWaitForTasksToCompleteOnShutdown "waitForTasksToCompleteOnShutdown"}. * <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 * <p>This flag will only have effect when the executor is running in a Spring
* application context and able to receive the {@link ContextClosedEvent}. * application context and able to receive the {@link ContextClosedEvent}.
* @since 6.1 * @since 6.1
* @see org.springframework.context.ConfigurableApplicationContext#close() * @see org.springframework.context.ConfigurableApplicationContext#close()
* @see DisposableBean#destroy() * @see DisposableBean#destroy()
* @see #shutdown() * @see #shutdown()
* @see #setAwaitTerminationSeconds
*/ */
public void setAcceptTasksAfterContextClose(boolean acceptTasksAfterContextClose) { public void setAcceptTasksAfterContextClose(boolean acceptTasksAfterContextClose) {
this.acceptTasksAfterContextClose = acceptTasksAfterContextClose; this.acceptTasksAfterContextClose = acceptTasksAfterContextClose;
@ -147,8 +153,8 @@ public abstract class ExecutorConfigurationSupport extends CustomizableThreadFac
/** /**
* Set whether to wait for scheduled tasks to complete on shutdown, * Set whether to wait for scheduled tasks to complete on shutdown,
* not interrupting running tasks and executing all tasks in the queue. * not interrupting running tasks and executing all tasks in the queue.
* <p>Default is {@code false}, with a coordinated lifecycle stop first (unless * <p>The default is {@code false}, with a coordinated lifecycle stop first
* {@link #setAcceptTasksAfterContextClose "acceptTasksAfterContextClose"} * (unless {@link #setAcceptTasksAfterContextClose "acceptTasksAfterContextClose"}
* has been set) and then an immediate shutdown through interrupting ongoing * has been set) and then an immediate shutdown through interrupting ongoing
* tasks and clearing the queue. Switch this flag to {@code true} if you * 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. * prefer fully completed tasks at the expense of a longer shutdown phase.
@ -162,6 +168,8 @@ public abstract class ExecutorConfigurationSupport extends CustomizableThreadFac
* property instead of or in addition to this property. * property instead of or in addition to this property.
* @see java.util.concurrent.ExecutorService#shutdown() * @see java.util.concurrent.ExecutorService#shutdown()
* @see java.util.concurrent.ExecutorService#shutdownNow() * @see java.util.concurrent.ExecutorService#shutdownNow()
* @see #shutdown()
* @see #setAwaitTerminationSeconds
*/ */
public void setWaitForTasksToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown) { public void setWaitForTasksToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown) {
this.waitForTasksToCompleteOnShutdown = waitForJobsToCompleteOnShutdown; this.waitForTasksToCompleteOnShutdown = waitForJobsToCompleteOnShutdown;
@ -326,7 +334,7 @@ public abstract class ExecutorConfigurationSupport extends CustomizableThreadFac
} }
/** /**
* Cancel the given remaining task which never commended execution, * Cancel the given remaining task which never commenced execution,
* as returned from {@link ExecutorService#shutdownNow()}. * as returned from {@link ExecutorService#shutdownNow()}.
* @param task the task to cancel (typically a {@link RunnableFuture}) * @param task the task to cancel (typically a {@link RunnableFuture})
* @since 5.0.5 * @since 5.0.5