jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1240053 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatImpl.java
Date Fri, 03 Feb 2012 09:53:40 GMT
Author: alexparvulescu
Date: Fri Feb  3 09:53:40 2012
New Revision: 1240053

URL: http://svn.apache.org/viewvc?rev=1240053&view=rev
Log:
JCR-3225 ConcurrentModificationException in QueryStatImpl

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatImpl.java?rev=1240053&r1=1240052&r2=1240053&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatImpl.java
Fri Feb  3 09:53:40 2012
@@ -115,16 +115,19 @@ public class QueryStatImpl implements Qu
         final QueryStatDtoImpl qs = new QueryStatDtoImpl(language, statement,
                 durationMs);
         slowQueries.offer(qs);
-        Iterator<QueryStatDtoImpl> iterator = popularQueries.iterator();
-        while (iterator.hasNext()) {
-            QueryStatDtoImpl qsdi = iterator.next();
-            if (qsdi.equals(qs)) {
-                qs.setOccurrenceCount(qsdi.getOccurrenceCount() + 1);
-                iterator.remove();
-                break;
+
+        synchronized (popularQueries) {
+            Iterator<QueryStatDtoImpl> iterator = popularQueries.iterator();
+            while (iterator.hasNext()) {
+                QueryStatDtoImpl qsdi = iterator.next();
+                if (qsdi.equals(qs)) {
+                    qs.setOccurrenceCount(qsdi.getOccurrenceCount() + 1);
+                    iterator.remove();
+                    break;
+                }
             }
+            popularQueries.offer(qs);
         }
-        popularQueries.offer(qs);
     }
 
     public void clearSlowQueriesQueue() {
@@ -142,11 +145,17 @@ public class QueryStatImpl implements Qu
     }
 
     public QueryStatDto[] getPopularQueries() {
-        QueryStatDtoImpl[] top = popularQueries
-                .toArray(new QueryStatDtoImpl[popularQueries.size()]);
+        QueryStatDtoImpl[] top = new QueryStatDtoImpl[0];
+        int size = 0;
+        int maxSize = 0;
+        synchronized (popularQueries) {
+            top = popularQueries.toArray(new QueryStatDtoImpl[popularQueries
+                    .size()]);
+            size = popularQueries.size();
+            maxSize = popularQueries.getMaxSize();
+        }
         Arrays.sort(top, Collections.reverseOrder(comparatorOccurrence));
-        int retSize = Math.min(popularQueries.size(),
-                popularQueries.getMaxSize() / POPULAR_QUEUE_MULTIPLIER);
+        int retSize = Math.min(size, maxSize / POPULAR_QUEUE_MULTIPLIER);
         QueryStatDto[] retval = new QueryStatDto[retSize];
         for (int i = 0; i < retSize; i++) {
             top[i].setPosition(i + 1);



Mime
View raw message