Skip to content

Commit 489df24

Browse files
committed
Access directReplyToContainers map only via lock
remove double checking for null container
1 parent 63e685a commit 489df24

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitTemplate.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,25 +1627,23 @@ private Message doSendAndReceiveWithDirect(String exchange, String routingKey, M
16271627
if (this.usePublisherConnection && connectionFactory.getPublisherConnectionFactory() != null) {
16281628
connectionFactory = connectionFactory.getPublisherConnectionFactory();
16291629
}
1630-
DirectReplyToMessageListenerContainer container = this.directReplyToContainers.get(connectionFactory);
1631-
if (container == null) {
1632-
synchronized (this.directReplyToContainers) {
1633-
container = this.directReplyToContainers.get(connectionFactory);
1634-
if (container == null) {
1635-
container = new DirectReplyToMessageListenerContainer(connectionFactory);
1636-
container.setMessageListener(this);
1637-
container.setBeanName(this.beanName + "#" + this.containerInstance.getAndIncrement());
1638-
if (this.taskExecutor != null) {
1639-
container.setTaskExecutor(this.taskExecutor);
1640-
}
1641-
if (this.afterReceivePostProcessors != null) {
1642-
container.setAfterReceivePostProcessors(this.afterReceivePostProcessors
1643-
.toArray(new MessagePostProcessor[this.afterReceivePostProcessors.size()]));
1644-
}
1645-
container.start();
1646-
this.directReplyToContainers.put(connectionFactory, container);
1647-
this.replyAddress = Address.AMQ_RABBITMQ_REPLY_TO;
1630+
DirectReplyToMessageListenerContainer container;
1631+
synchronized (this.directReplyToContainers) {
1632+
container = this.directReplyToContainers.get(connectionFactory);
1633+
if (container == null) {
1634+
container = new DirectReplyToMessageListenerContainer(connectionFactory);
1635+
container.setMessageListener(this);
1636+
container.setBeanName(this.beanName + "#" + this.containerInstance.getAndIncrement());
1637+
if (this.taskExecutor != null) {
1638+
container.setTaskExecutor(this.taskExecutor);
1639+
}
1640+
if (this.afterReceivePostProcessors != null) {
1641+
container.setAfterReceivePostProcessors(this.afterReceivePostProcessors
1642+
.toArray(new MessagePostProcessor[this.afterReceivePostProcessors.size()]));
16481643
}
1644+
container.start();
1645+
this.directReplyToContainers.put(connectionFactory, container);
1646+
this.replyAddress = Address.AMQ_RABBITMQ_REPLY_TO;
16491647
}
16501648
}
16511649
ChannelHolder channelHolder = container.getChannelHolder();

0 commit comments

Comments
 (0)