AMQP-223 Fix Consumer Thread Management
If doStart() was called multiple times, multiple threads ran in each consumer. There is a check to prevent creating multiple consumers in this case, but the thread management had no such check.
This commit is contained in:
committed by
Oleg Zhurakousky
parent
c4170ce40f
commit
628707ee32
@@ -292,9 +292,17 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
|
||||
protected void doStart() throws Exception {
|
||||
super.doStart();
|
||||
synchronized (this.consumersMonitor) {
|
||||
initializeConsumers();
|
||||
int newConsumers = initializeConsumers();
|
||||
if (this.consumers == null) {
|
||||
logger.info("Consumers were initialized and then cleared (presumably the container was stopped concurrently)");
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Consumers were initialized and then cleared (presumably the container was stopped concurrently)");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (newConsumers <= 0) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Consumers are already running");
|
||||
}
|
||||
return;
|
||||
}
|
||||
Set<AsyncMessageProcessingConsumer> processors = new HashSet<AsyncMessageProcessingConsumer>();
|
||||
@@ -343,7 +351,8 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
|
||||
|
||||
}
|
||||
|
||||
protected void initializeConsumers() {
|
||||
protected int initializeConsumers() {
|
||||
int count = 0;
|
||||
synchronized (this.consumersMonitor) {
|
||||
if (this.consumers == null) {
|
||||
cancellationLock.reset();
|
||||
@@ -351,9 +360,11 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
|
||||
for (int i = 0; i < this.concurrentConsumers; i++) {
|
||||
BlockingQueueConsumer consumer = createBlockingQueueConsumer();
|
||||
this.consumers.add(consumer);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
protected boolean isChannelLocallyTransacted(Channel channel) {
|
||||
|
||||
Reference in New Issue
Block a user