cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clecl...@apache.org
Subject svn commit: r910414 - /cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java
Date Tue, 16 Feb 2010 07:08:11 GMT
Author: cleclerc
Date: Tue Feb 16 07:08:11 2010
New Revision: 910414

URL: http://svn.apache.org/viewvc?rev=910414&view=rev
Log:
[CXF-2676] JMX InstanceAlreadyExistsException under high load initialization
Add lock around counter creation

Modified:
    cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java

Modified: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java?rev=910414&r1=910413&r2=910414&view=diff
==============================================================================
--- cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java
(original)
+++ cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java
Tue Feb 16 07:08:11 2010
@@ -21,6 +21,8 @@
 
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -47,6 +49,7 @@
     
     private Map<ObjectName, Counter> counters;
     private Bus bus;
+    private Lock counterCreationLock = new ReentrantLock();
     
     public CounterRepository() {
         counters = new ConcurrentHashMap<ObjectName, Counter>();
@@ -83,9 +86,18 @@
     
     public void increaseCounter(ObjectName on, MessageHandlingTimeRecorder mhtr) {
         Counter counter = getCounter(on);
-        if (null == counter) {            
-            counter = createCounter(on, mhtr);
-            counters.put(on, counter);
+        if (null == counter) {
+            counterCreationLock.lock();
+            try {
+                // check if the counter has been created during the locked time
+                counter = getCounter(on);
+                if (counter == null) {
+                    counter = createCounter(on, mhtr);
+                    counters.put(on, counter);
+                }
+            } finally {
+                counterCreationLock.unlock();
+            }
         }
         counter.increase(mhtr);        
         if (LOG.isLoggable(Level.FINE)) {



Mime
View raw message