[jboss-cvs] JBossAS SVN: r107590 - projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/statistics.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Aug 13 07:23:00 EDT 2010
Author: wolfc
Date: 2010-08-13 07:22:59 -0400 (Fri, 13 Aug 2010)
New Revision: 107590
Modified:
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/statistics/InvocationStatistics.java
Log:
EJBTHREE-2146: using atomics instead of synchronized methods
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/statistics/InvocationStatistics.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/statistics/InvocationStatistics.java 2010-08-13 11:21:38 UTC (rev 107589)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/statistics/InvocationStatistics.java 2010-08-13 11:22:59 UTC (rev 107590)
@@ -29,6 +29,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
/** A method invocation statistics collection class.
*
@@ -42,25 +43,25 @@
/** The method invocations */
private Map<String, TimeStatistic> methodStats;
- public long concurrentCalls = 0;
- public long maxConcurrentCalls = 0;
+ public AtomicLong concurrentCalls = new AtomicLong();
+ public volatile long maxConcurrentCalls = 0;
public long lastResetTime = System.currentTimeMillis();
public class TimeStatistic implements Serializable
{
private static final long serialVersionUID = -3717837456831579570L;
- public volatile long count;
+ public AtomicLong count = new AtomicLong();
public volatile long minTime = Long.MAX_VALUE;
public volatile long maxTime;
- public volatile long totalTime;
+ public AtomicLong totalTime = new AtomicLong();
public void reset()
{
- count = 0;
+ count.set(0);
minTime = Long.MAX_VALUE;
maxTime = 0;
- totalTime = 0;
+ totalTime.set(0);
}
}
@@ -75,32 +76,41 @@
* @param m the method to update the statistics for.
* @param elapsed the elapsed time in milliseconds for the invocation.
*/
- public synchronized void updateStats(Method m, long elapsed)
+ public void updateStats(Method m, long elapsed)
{
- TimeStatistic stat = (TimeStatistic) methodStats.get(m.getName());
+ TimeStatistic stat = methodStats.get(m.getName());
if (stat == null)
{
- stat = new TimeStatistic();
- methodStats.put(m.getName(), stat);
+ synchronized (methodStats)
+ {
+ stat = methodStats.get(m.getName());
+ if (stat == null)
+ {
+ stat = new TimeStatistic();
+ methodStats.put(m.getName(), stat);
+ }
+ }
}
- stat.count++;
- stat.totalTime += elapsed;
+ // Does it really matter if a stat is off for a tick?
+ stat.count.incrementAndGet();
+ stat.totalTime.addAndGet(elapsed);
+ // Eventually it'll be close to accurate
if (stat.minTime > elapsed)
stat.minTime = elapsed;
if (stat.maxTime < elapsed)
stat.maxTime = elapsed;
}
- public synchronized void callIn()
+ public void callIn()
{
- concurrentCalls++;
- if (concurrentCalls > maxConcurrentCalls)
- maxConcurrentCalls = concurrentCalls;
+ long calls = concurrentCalls.incrementAndGet();
+ if (calls > maxConcurrentCalls)
+ maxConcurrentCalls = calls;
}
- public synchronized void callOut()
+ public void callOut()
{
- concurrentCalls--;
+ concurrentCalls.decrementAndGet();
}
/** Resets all current TimeStatistics.
More information about the jboss-cvs-commits
mailing list