Browse Source

avoid double closing in case of shutdown hook (SPR-6793)

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@2941 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Juergen Hoeller 16 years ago
parent
commit
0760179df8
  1. 11
      org.springframework.context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

11
org.springframework.context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

@ -176,6 +176,9 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader @@ -176,6 +176,9 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
/** Flag that indicates whether this context is currently active */
private boolean active = false;
/** Flag that indicates whether this context has been closed already */
private boolean closed = false;
/** Synchronization monitor for the "active" flag */
private final Object activeMonitor = new Object();
@ -964,7 +967,13 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader @@ -964,7 +967,13 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
* @see #registerShutdownHook()
*/
protected void doClose() {
if (isActive()) {
boolean actuallyClose;
synchronized (this.activeMonitor) {
actuallyClose = this.active && !this.closed;
this.closed = true;
}
if (actuallyClose) {
if (logger.isInfoEnabled()) {
logger.info("Closing " + this);
}

Loading…
Cancel
Save