diff --git a/spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java b/spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java index 5ab288ed35..2038e662ca 100644 --- a/spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -38,6 +38,7 @@ import org.springframework.lang.Nullable; * * @author Juergen Hoeller * @author Chris Beams + * @author Sam Brannen * @since 03.11.2003 */ public interface ConfigurableApplicationContext extends ApplicationContext, Lifecycle, Closeable { @@ -86,6 +87,14 @@ public interface ConfigurableApplicationContext extends ApplicationContext, Life */ String SYSTEM_ENVIRONMENT_BEAN_NAME = "systemEnvironment"; + /** + * {@link Thread#getName() Name} of the {@linkplain #registerShutdownHook() + * shutdown hook} thread: {@value}. + * @since 5.2 + * @see #registerShutdownHook() + */ + String SHUTDOWN_HOOK_THREAD_NAME = "SpringContextShutdownHook"; + /** * Set the unique id of this application context. @@ -164,6 +173,8 @@ public interface ConfigurableApplicationContext extends ApplicationContext, Life * on JVM shutdown unless it has already been closed at that time. *

This method can be called multiple times. Only one shutdown hook * (at max) will be registered for each context instance. + *

As of Spring Framework 5.2, the {@linkplain Thread#getName() name} of + * the shutdown hook thread should be {@link #SHUTDOWN_HOOK_THREAD_NAME}. * @see java.lang.Runtime#addShutdownHook * @see #close() */ diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java index b707f0df05..6b4e5b6a4f 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java @@ -115,6 +115,7 @@ import org.springframework.util.ReflectionUtils; * @author Juergen Hoeller * @author Mark Fisher * @author Stephane Nicoll + * @author Sam Brannen * @since January 21, 2001 * @see #refreshBeanFactory * @see #getBeanFactory @@ -927,10 +928,12 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader /** - * Register a shutdown hook with the JVM runtime, closing this context - * on JVM shutdown unless it has already been closed at that time. + * Register a shutdown hook {@linkplain Thread#getName() named} + * {@code SpringContextShutdownHook} with the JVM runtime, closing this + * context on JVM shutdown unless it has already been closed at that time. *

Delegates to {@code doClose()} for the actual closing procedure. * @see Runtime#addShutdownHook + * @see ConfigurableApplicationContext#SHUTDOWN_HOOK_THREAD_NAME * @see #close() * @see #doClose() */ @@ -938,7 +941,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader public void registerShutdownHook() { if (this.shutdownHook == null) { // No shutdown hook registered yet. - this.shutdownHook = new Thread() { + this.shutdownHook = new Thread(SHUTDOWN_HOOK_THREAD_NAME) { @Override public void run() { synchronized (startupShutdownMonitor) {