From 6561490fd9b9b8f2fa7b879c7cd37ff5fed30bf2 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 17 Jun 2024 21:08:28 +0200 Subject: [PATCH] Expose isClosed() method on AbstractApplicationContext Closes gh-33058 --- .../context/ConfigurableApplicationContext.java | 12 ++++++++++++ .../context/support/AbstractApplicationContext.java | 5 +++++ 2 files changed, 17 insertions(+) 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 1641d5fb920b..522102b22704 100644 --- a/spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java @@ -242,6 +242,18 @@ public interface ConfigurableApplicationContext extends ApplicationContext, Life @Override void close(); + /** + * Return whether this context has been closed already, that is, + * whether {@link #close()} has been called on an active context + * in order to initiate its shutdown. + *

Note: This does not indicate whether context shutdown has completed. + * Use {@link #isActive()} for differentiating between those scenarios: + * a context becomes inactive once it has been fully shut down and the + * original {@code close()} call has returned. + * @since 6.2 + */ + boolean isClosed(); + /** * Determine whether this application context is active, that is, * whether it has been refreshed at least once and has not been closed yet. 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 8f18ac6dc1b3..56985b3b6df2 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 @@ -1222,6 +1222,11 @@ protected void onClose() { // For subclasses: do nothing by default. } + @Override + public boolean isClosed() { + return this.closed.get(); + } + @Override public boolean isActive() { return this.active.get();