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--2024-11-13--si X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=fad48e1de38c681d2d33e7e6136536e862901474;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 715a97a..804e247 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 723a8d0..ace87a9 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(); } }