Browse Source

Expose isClosed() method on AbstractApplicationContext

Closes gh-33058
pull/33065/head
Juergen Hoeller 2 years ago
parent
commit
6561490fd9
  1. 12
      spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java
  2. 5
      spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

12
spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java

@ -242,6 +242,18 @@ public interface ConfigurableApplicationContext extends ApplicationContext, Life @@ -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.
* <p>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.

5
spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

@ -1222,6 +1222,11 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader @@ -1222,6 +1222,11 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
// For subclasses: do nothing by default.
}
@Override
public boolean isClosed() {
return this.closed.get();
}
@Override
public boolean isActive() {
return this.active.get();

Loading…
Cancel
Save