package com.yanzuoguang.log; /** * 次数统计 * * @author 颜佐光 */ public class LogUrlCountVo { private final Object lockStart = new Object(); private final Object lockFinish = new Object(); private volatile String url; private volatile int level; private volatile int startCount; private volatile int endCount; private volatile int errorCount; private volatile long totalTime; private volatile long avgTime; private volatile long minTime = Long.MAX_VALUE; private volatile long maxTime; public LogUrlCountVo(String url, int level) { this.url = url; } public void addFinish(long time, boolean isLog) { synchronized (lockFinish) { this.startCount++; this.endCount++; if (isLog) { this.errorCount++; } this.totalTime += time; this.minTime = Math.min(time, this.minTime); this.maxTime = Math.max(time, this.maxTime); this.avgTime = this.totalTime / this.endCount; } } public void subFinish(long time, boolean isLog) { synchronized (lockFinish) { this.startCount--; this.endCount--; if (isLog) { this.errorCount--; } this.totalTime -= time; this.avgTime = this.totalTime / this.endCount; } } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public int getLevel() { return level; } public void setLevel(int level) { this.level = level; } public int getStartCount() { return startCount; } public void setStartCount(int startCount) { this.startCount = startCount; } public int getEndCount() { return endCount; } public void setEndCount(int endCount) { this.endCount = endCount; } public int getErrorCount() { return errorCount; } public void setErrorCount(int errorCount) { this.errorCount = errorCount; } public long getTotalTime() { return totalTime; } public void setTotalTime(long totalTime) { this.totalTime = totalTime; } public long getAvgTime() { return avgTime; } public void setAvgTime(long avgTime) { this.avgTime = avgTime; } public long getMinTime() { return minTime; } public void setMinTime(long minTime) { this.minTime = minTime; } public long getMaxTime() { return maxTime; } public void setMaxTime(long maxTime) { this.maxTime = maxTime; } }