|
28 | 28 | import java.util.Map; |
29 | 29 | import java.util.Map.Entry; |
30 | 30 | import java.util.concurrent.BlockingQueue; |
| 31 | +import java.util.concurrent.ConcurrentHashMap; |
| 32 | +import java.util.concurrent.ConcurrentMap; |
31 | 33 | import java.util.concurrent.LinkedBlockingQueue; |
32 | 34 | import java.util.concurrent.ScheduledFuture; |
33 | 35 |
|
@@ -320,7 +322,7 @@ private final class ListenerConsumer implements SchedulingAwareRunnable, Consume |
320 | 322 |
|
321 | 323 | private final Consumer<K, V> consumer; |
322 | 324 |
|
323 | | - private final Map<String, Map<Integer, Long>> offsets = new HashMap<>(); |
| 325 | + private final ConcurrentMap<String, ConcurrentMap<Integer, Long>> offsets = new ConcurrentHashMap<>(); |
324 | 326 |
|
325 | 327 | private final GenericMessageListener<?> genericListener; |
326 | 328 |
|
@@ -1202,7 +1204,7 @@ record = this.acks.poll(); |
1202 | 1204 | } |
1203 | 1205 |
|
1204 | 1206 | private void addOffset(ConsumerRecord<K, V> record) { |
1205 | | - this.offsets.computeIfAbsent(record.topic(), v -> new HashMap<>()) |
| 1207 | + this.offsets.computeIfAbsent(record.topic(), v -> new ConcurrentHashMap<>()) |
1206 | 1208 | .compute(record.partition(), (k, v) -> v == null ? record.offset() : Math.max(v, record.offset())); |
1207 | 1209 | } |
1208 | 1210 |
|
@@ -1230,7 +1232,7 @@ private void commitIfNecessary() { |
1230 | 1232 |
|
1231 | 1233 | private Map<TopicPartition, OffsetAndMetadata> buildCommits() { |
1232 | 1234 | Map<TopicPartition, OffsetAndMetadata> commits = new HashMap<>(); |
1233 | | - for (Entry<String, Map<Integer, Long>> entry : this.offsets.entrySet()) { |
| 1235 | + for (Entry<String, ConcurrentMap<Integer, Long>> entry : this.offsets.entrySet()) { |
1234 | 1236 | for (Entry<Integer, Long> offset : entry.getValue().entrySet()) { |
1235 | 1237 | commits.put(new TopicPartition(entry.getKey(), offset.getKey()), |
1236 | 1238 | new OffsetAndMetadata(offset.getValue() + 1)); |
|
0 commit comments