mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
bug #I3CT9A 监控打印的耗时不准确问题
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user