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
This commit is contained in:
parent
16e4c7aa2e
commit
0760179df8
|
|
@ -176,6 +176,9 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||||
/** Flag that indicates whether this context is currently active */
|
/** Flag that indicates whether this context is currently active */
|
||||||
private boolean active = false;
|
private boolean active = false;
|
||||||
|
|
||||||
|
/** Flag that indicates whether this context has been closed already */
|
||||||
|
private boolean closed = false;
|
||||||
|
|
||||||
/** Synchronization monitor for the "active" flag */
|
/** Synchronization monitor for the "active" flag */
|
||||||
private final Object activeMonitor = new Object();
|
private final Object activeMonitor = new Object();
|
||||||
|
|
||||||
|
|
@ -964,7 +967,13 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||||
* @see #registerShutdownHook()
|
* @see #registerShutdownHook()
|
||||||
*/
|
*/
|
||||||
protected void doClose() {
|
protected void doClose() {
|
||||||
if (isActive()) {
|
boolean actuallyClose;
|
||||||
|
synchronized (this.activeMonitor) {
|
||||||
|
actuallyClose = this.active && !this.closed;
|
||||||
|
this.closed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actuallyClose) {
|
||||||
if (logger.isInfoEnabled()) {
|
if (logger.isInfoEnabled()) {
|
||||||
logger.info("Closing " + this);
|
logger.info("Closing " + this);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue