From: Kai Moritz Date: Sat, 9 Nov 2024 15:56:32 +0000 (+0100) Subject: Mögliche Exception wegen konkurrierendem Zugriff auf Map verhindert X-Git-Tag: consumer/spring-consumer--log-compaction--2025-01-signal X-Git-Url: https://juplo.de/gitweb/?a=commitdiff_plain;h=432aae1434666b57704bfca363dc4ff3cf47f691;p=demos%2Fkafka%2Ftraining Mögliche Exception wegen konkurrierendem Zugriff auf Map verhindert --- diff --git a/src/main/java/de/juplo/kafka/CounterState.java b/src/main/java/de/juplo/kafka/CounterState.java index 715a97a1..804e247a 100644 --- a/src/main/java/de/juplo/kafka/CounterState.java +++ b/src/main/java/de/juplo/kafka/CounterState.java @@ -19,6 +19,6 @@ public class CounterState public synchronized Map getCounterState() { - return counterState; + return new HashMap<>(counterState); } } diff --git a/src/main/java/de/juplo/kafka/CounterStateController.java b/src/main/java/de/juplo/kafka/CounterStateController.java index 723a8d0d..ace87a95 100644 --- a/src/main/java/de/juplo/kafka/CounterStateController.java +++ b/src/main/java/de/juplo/kafka/CounterStateController.java @@ -4,7 +4,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.HashMap; import java.util.Map; @@ -17,6 +16,6 @@ public class CounterStateController @GetMapping Map> getAllCounters() { - return new HashMap<>(consumer.getCounterState()); + return consumer.getCounterState(); } }