[#5] 컨슈머 코드 마이그레이션 #6
@ -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();
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user