Skip to content

Commit 110a3ce

Browse files
mipo256spring-builds
authored andcommitted
Altered the example in EmbeddedKafkaHolder usage (#3929)
Integration tests with an EmbeddedKafka instance are sometimes run in parallel in Junit. The current example is not thread safe, so I think the oficial documentation should account for that. Signed-off-by: mipo256 <[email protected]> (cherry picked from commit 579e7cb)
1 parent 83abedf commit 110a3ce

File tree

1 file changed

+11
-12
lines changed
  • spring-kafka-docs/src/main/antora/modules/ROOT/pages

1 file changed

+11
-12
lines changed

spring-kafka-docs/src/main/antora/modules/ROOT/pages/testing.adoc

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,21 +180,20 @@ public final class EmbeddedKafkaHolder {
180180
181181
public static EmbeddedKafkaBroker getEmbeddedKafka() {
182182
if (!started) {
183-
try {
184-
embeddedKafka.afterPropertiesSet();
185-
}
186-
catch (Exception e) {
187-
throw new KafkaException("Embedded broker failed to start", e);
188-
}
189-
started = true;
183+
synchronized (this) {
184+
if (!started) {
185+
try {
186+
embeddedKafka.afterPropertiesSet();
187+
}
188+
catch (Exception e) {
189+
throw new KafkaException("Embedded broker failed to start", e);
190+
}
191+
started = true;
192+
}
193+
}
190194
}
191195
return embeddedKafka;
192196
}
193-
194-
private EmbeddedKafkaHolder() {
195-
super();
196-
}
197-
198197
}
199198
----
200199

0 commit comments

Comments
 (0)