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

This commit is contained in:
Juergen Hoeller 2010-02-10 13:49:51 +00:00
parent 63f574e741
commit 03e9e4568f
1 changed files with 10 additions and 1 deletions

View File

@ -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
* @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);
}