Skip to content

Commit 579e7cb

Browse files
authored
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. **Auto-cherry-pick to `3.3.x` & `3.2.x`** Signed-off-by: mipo256 <[email protected]>
1 parent 7b71d20 commit 579e7cb

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
@@ -162,21 +162,20 @@ public final class EmbeddedKafkaHolder {
162162
163163
public static EmbeddedKafkaBroker getEmbeddedKafka() {
164164
if (!started) {
165-
try {
166-
embeddedKafka.afterPropertiesSet();
167-
}
168-
catch (Exception e) {
169-
throw new KafkaException("Embedded broker failed to start", e);
170-
}
171-
started = true;
165+
synchronized (this) {
166+
if (!started) {
167+
try {
168+
embeddedKafka.afterPropertiesSet();
169+
}
170+
catch (Exception e) {
171+
throw new KafkaException("Embedded broker failed to start", e);
172+
}
173+
started = true;
174+
}
175+
}
172176
}
173177
return embeddedKafka;
174178
}
175-
176-
private EmbeddedKafkaHolder() {
177-
super();
178-
}
179-
180179
}
181180
----
182181

0 commit comments

Comments
 (0)