Mögliche Exception wegen konkurrierendem Zugriff auf Map verhindert consumer/spring-consumer--log-compaction consumer/spring-consumer--log-compaction--2024-11-13--si
authorKai Moritz <kai@juplo.de>
Sat, 9 Nov 2024 15:56:32 +0000 (16:56 +0100)
committerKai Moritz <kai@juplo.de>
Sun, 10 Nov 2024 13:27:50 +0000 (14:27 +0100)
src/main/java/de/juplo/kafka/CounterState.java
src/main/java/de/juplo/kafka/CounterStateController.java

index 715a97a..804e247 100644 (file)
@@ -19,6 +19,6 @@ public class CounterState
 
   public synchronized Map<String, Long> getCounterState()
   {
-    return counterState;
+    return new HashMap<>(counterState);
   }
 }
index 723a8d0..ace87a9 100644 (file)
@@ -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<Integer, Map<String, Long>> getAllCounters()
   {
-    return new HashMap<>(consumer.getCounterState());
+    return consumer.getCounterState();
   }
 }