欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Java 统计类使用示例

最编程 2024-04-07 10:46:16
...

实例1: reset

import javax.management.j2ee.statistics.Statistic; //导入依赖的package包/类
public void reset() {
    Statistic[] stats = getStatistics();
    int size = stats.length;
    for (int i = 0; i < size; i++) {
        Statistic stat = stats[i];
        if (stat instanceof Resettable) {
            Resettable r = (Resettable) stat;
            r.reset();
        }
    }
}
 

实例2: getStatistic

import javax.management.j2ee.statistics.Statistic; //导入依赖的package包/类
public Statistic getStatistic(String name) {
    for (StatisticImpl stat : this.set) {
        if (stat.getName() != null && stat.getName().equals(name)) {
            return stat;
        }
    }
    return null;
}
 

实例3: StatsSimplifier

import javax.management.j2ee.statistics.Statistic; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected StatsSimplifier(Class<T> type) {
       super(type);
       addExtractor("statistics", new AttributeExtractor<T>() {
           public Object extract(Stats value) throws SkipAttributeException {
               Map<String, Statistic> result = new HashMap<String, Statistic>();
               for (String name : value.getStatisticNames()) {
                   result.put(name, value.getStatistic(name));
               }
               return result;
           }
       });
   }
 

推荐阅读