[#5] 컨슈머 코드 마이그레이션 #6

Merged
pricelees merged 9 commits from feature/#5 into main 2025-06-27 05:43:39 +00:00
Showing only changes of commit ce20f85c04 - Show all commits

View File

@ -0,0 +1,30 @@
package com.sangdol.consumer.infrastructure.kafka.consumer;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
public class ConsumerStats {
private final int workerThreads;
private final Map<String, Long> threadElapsedTime;
public ConsumerStats(int workerThreads) {
this.workerThreads = workerThreads;
this.threadElapsedTime = new ConcurrentHashMap<>();
}
public void update(long elapsedTime) {
threadElapsedTime.put(Thread.currentThread().getName(), elapsedTime);
}
public long averageTime() {
if (threadElapsedTime.size() != workerThreads) {
return 0L;
}
return threadElapsedTime.values().stream()
.collect(Collectors.averagingLong(Long::longValue))
.longValue();
}
}