bug #I3CT9A 监控打印的耗时不准确问题

This commit is contained in:
zendwang
2021-03-26 16:46:37 +08:00
parent be6d85c289
commit c6545469f6
2 changed files with 30 additions and 3 deletions

View File

@@ -88,10 +88,9 @@ public class MonitorBus {
public void printStatistics(){
try{
Map<String, BigDecimal> compAverageTimeSpent = new HashMap<String, BigDecimal>();
long totalTimeSpent = 0;
for(Entry<String, BoundedPriorityQueue<CompStatistics>> entry : statisticsMap.entrySet()){
long totalTimeSpent = 0;
for(CompStatistics statistics : entry.getValue()){
totalTimeSpent += statistics.getTimeSpent();
}

View File

@@ -0,0 +1,28 @@
package com.yomahub.liteflow.monitor;
import java.util.Iterator;
import java.util.PriorityQueue;
import cn.hutool.core.collection.BoundedPriorityQueue;
import cn.hutool.core.util.RandomUtil;
import org.junit.Test;
import com.yomahub.liteflow.entity.monitor.CompStatistics;
public class BoundedPriorityQueueTest {
@Test
public void test() throws InterruptedException {
PriorityQueue<CompStatistics> queue = new BoundedPriorityQueue<>(6);
for (int i = 0; i < 20 ; i ++) {
long randomTime = RandomUtil.randomLong(20);
Thread.sleep(randomTime);
queue.add(new CompStatistics("comp" + i, randomTime));
}
Iterator<CompStatistics> iterator = queue.iterator();
while(iterator.hasNext()) {
CompStatistics compStatistics = iterator.next();
System.out.println(compStatistics.getComponentClazzName() + " " + compStatistics.getTimeSpent());
}
}
}