INT-3634 Fix race condition in the DHCRegistry

JIRA: https://jira.spring.io/browse/INT-3634
This commit is contained in:
Gary Russell
2015-02-12 14:25:28 -05:00
committed by Artem Bilan
parent ec4453a3ee
commit a9ff56174e
2 changed files with 8 additions and 14 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -236,17 +236,15 @@ public class DefaultHeaderChannelRegistry extends IntegrationObjectSupport
* Cancel the scheduled reap task and run immediately; then reschedule.
*/
@Override
public void runReaper() {
synchronized(this) {
this.reaperScheduledFuture.cancel(false);
this.reaperScheduledFuture = null;
public synchronized void runReaper() {
if (this.reaperScheduledFuture != null) {
this.reaperScheduledFuture.cancel(true);
}
this.run();
}
@Override
public void run() {
this.reaperScheduledFuture = null;
public synchronized void run() {
if (logger.isTraceEnabled()) {
logger.trace("Reaper started; channels size=" + this.channels.size());
}
@@ -261,12 +259,8 @@ public class DefaultHeaderChannelRegistry extends IntegrationObjectSupport
iterator.remove();
}
}
synchronized (this) {
if (this.reaperScheduledFuture == null) {
this.reaperScheduledFuture = this.getTaskScheduler().schedule(this,
new Date(System.currentTimeMillis() + this.reaperDelay));
}
}
this.reaperScheduledFuture = this.getTaskScheduler().schedule(this,
new Date(System.currentTimeMillis() + this.reaperDelay));
if (logger.isTraceEnabled()) {
logger.trace("Reaper completed; channels size=" + this.channels.size());
}