DATAREDIS-415 - Handle InterruptedException correctly in RedisMessageListenerContainer.

Set interrupted bit when catching InterruptedException. Exit loops when catching InterruptedException to free resources.

Original Pull Request: #168
This commit is contained in:
Mark Paluch
2016-02-15 12:27:33 +01:00
committed by Christoph Strobl
parent 80f8867763
commit 7da09eaa51
3 changed files with 129 additions and 9 deletions

View File

@@ -242,8 +242,11 @@ public class ClusterCommandExecutor implements DisposableBean {
exceptions.put(entry.getKey(), ex != null ? ex : e.getCause());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
RuntimeException ex = convertToDataAccessExeption((Exception) e.getCause());
exceptions.put(entry.getKey(), ex != null ? ex : e.getCause());
break;
}
}
}

View File

@@ -67,6 +67,7 @@ import org.springframework.util.ErrorHandler;
* @author Jennifer Hickey
* @author Way Joke
* @author Thomas Darimont
* @author Mark Paluch
*/
public class RedisMessageListenerContainer implements InitializingBean, DisposableBean, BeanNameAware, SmartLifecycle {
@@ -204,6 +205,9 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab
monitor.wait(initWait);
} catch (InterruptedException e) {
// stop waiting
Thread.currentThread().interrupt();
running = false;
return;
}
}
}
@@ -658,6 +662,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab
Thread.sleep(this.recoveryInterval);
} catch (InterruptedException interEx) {
logger.debug("Thread interrupted while sleeping the recovery interval");
Thread.currentThread().interrupt();
}
}
}
@@ -700,7 +705,8 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab
try {
Thread.sleep(WAIT);
} catch (InterruptedException ex) {
done = true;
Thread.currentThread().interrupt();
return;
}
}
}
@@ -730,7 +736,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab
boolean asyncConnection = ConnectionUtils.isAsync(connectionFactory);
// NB: async drivers' Xsubscribe calls block, so we notify the RDMLC before performing the actual subscription.
// NB: sync drivers' Xsubscribe calls block, so we notify the RDMLC before performing the actual subscription.
if (!asyncConnection) {
synchronized (monitor) {
monitor.notify();
@@ -849,6 +855,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab
localMonitor.wait(subscriptionWait);
} catch (InterruptedException e) {
// Stop waiting
Thread.currentThread().interrupt();
}
}
if (!subscriptionTaskRunning) {
@@ -1004,16 +1011,18 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab
long startTime = System.currentTimeMillis();
while (!timedOut(startTime, timeout)) {
if (condition.passes()) {
return true;
}
try {
try {
while (!timedOut(startTime, timeout)) {
if (condition.passes()) {
return true;
}
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return false;
}