diff --git a/bindings/java/src/org/hyperic/sigar/CpuTimer.java b/bindings/java/src/org/hyperic/sigar/CpuTimer.java index df96aeb3..1fc76975 100644 --- a/bindings/java/src/org/hyperic/sigar/CpuTimer.java +++ b/bindings/java/src/org/hyperic/sigar/CpuTimer.java @@ -21,8 +21,14 @@ package org.hyperic.sigar; import org.hyperic.sigar.jmx.CpuTimerMBean; import java.io.PrintStream; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; public class CpuTimer implements CpuTimerMBean { + private static final Map timers = + Collections.synchronizedMap(new HashMap()); + private Sigar sigar; private long totalTime; private long cpuTotal; @@ -146,6 +152,15 @@ public class CpuTimer implements CpuTimerMBean { return this.stopTime; } + public static CpuTimer getInstance(String name) { + CpuTimer timer = (CpuTimer)timers.get(name); + if (timer == null) { + timer = new CpuTimer(); + timers.put(name, timer); + } + return timer; + } + public String format(long elap) { String fraction = (elap % 1000) + ""; int pad = 3 - fraction.length();