1 18 package org.apache.activemq.perf; 19 20 23 public class PerfRate{ 24 25 protected int totalCount; 26 protected int count; 27 protected long startTime=System.currentTimeMillis(); 28 29 32 public int getCount(){ 33 return totalCount; 34 } 35 36 synchronized public void increment(){ 37 totalCount++; 38 count++; 39 } 40 41 public int getRate(){ 42 long endTime=System.currentTimeMillis(); 43 long totalTime=endTime-startTime; 44 int result=(int) ((count*1000)/totalTime); 45 return result; 46 } 47 48 51 synchronized public PerfRate cloneAndReset() { 52 PerfRate rc = new PerfRate(); 53 rc.totalCount = totalCount; 54 rc.count=count; 55 rc.startTime=startTime; 56 count=0; 57 startTime=System.currentTimeMillis(); 58 return rc; 59 } 60 61 64 public void reset() { 65 count=0; 66 startTime=System.currentTimeMillis(); 67 } 68 69 72 public int getTotalCount(){ 73 return totalCount; 74 } 75 76 80 public void setTotalCount(int totalCount){ 81 this.totalCount=totalCount; 82 } 83 } 84 | Popular Tags |