From f715bbef8bafe5a3cfa9a786620d85a83926f29b Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Fri, 13 Apr 2018 16:22:28 -0400 Subject: [PATCH] GH-646: Avoid sync when no transaction --- .../kafka/core/DefaultKafkaProducerFactory.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spring-kafka/src/main/java/org/springframework/kafka/core/DefaultKafkaProducerFactory.java b/spring-kafka/src/main/java/org/springframework/kafka/core/DefaultKafkaProducerFactory.java index 7b514a9a..b0000605 100644 --- a/spring-kafka/src/main/java/org/springframework/kafka/core/DefaultKafkaProducerFactory.java +++ b/spring-kafka/src/main/java/org/springframework/kafka/core/DefaultKafkaProducerFactory.java @@ -302,9 +302,13 @@ public class DefaultKafkaProducerFactory implements ProducerFactory, } @Override - public synchronized void close() { - if (this.cache != null && !this.cache.contains(this)) { - this.cache.offer(this); + public void close() { + if (this.cache != null) { + synchronized (this) { + if (!this.cache.contains(this)) { + this.cache.offer(this); + } + } } }