jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r469853 - /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
Date Wed, 01 Nov 2006 10:50:23 GMT
Author: tripod
Date: Wed Nov  1 02:50:23 2006
New Revision: 469853

URL: http://svn.apache.org/viewvc?view=rev&rev=469853
Log:
[JCR-614] Weird locking behaviour in CachingHierarchyManager

Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java?view=diff&rev=469853&r1=469852&r2=469853
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
Wed Nov  1 02:50:23 2006
@@ -30,14 +30,15 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jcr.ItemNotFoundException;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.RepositoryException;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+
 /**
  * Implementation of a <code>HierarchyManager</code> that caches paths of
  * items.
@@ -465,7 +466,19 @@
                 return;
             }
             if (idCache.size() >= upperLimit) {
-                removeLRU();
+                /**
+                 * Remove least recently used item. Scans the LRU list from head to tail
+                 * and removes the first item that has no children.
+                 */
+                LRUEntry entry = head;
+                while (entry != null) {
+                    PathMap.Element element = entry.getElement();
+                    if (element.getChildrenCount() == 0) {
+                        evict(entry, true);
+                        return;
+                    }
+                    entry = entry.getNext();
+                }
             }
 
             PathMap.Element element = pathCache.put(path);
@@ -481,24 +494,6 @@
     }
 
     /**
-     * Remove least recently used item. Scans the LRU list from head to tail
-     * and removes the first item that has no children.
-     */
-    private void removeLRU() {
-        synchronized (cacheMonitor) {
-            LRUEntry entry = head;
-            while (entry != null) {
-                PathMap.Element element = entry.getElement();
-                if (element.getChildrenCount() == 0) {
-                    evict(entry, true);
-                    return;
-                }
-                entry = entry.getNext();
-            }
-        }
-    }
-
-    /**
      * Return a flag indicating whether a certain element is cached.
      *
      * @param id item id
@@ -534,15 +529,14 @@
      * @param removeFromPathCache whether to remove from path cache
      */
     private void remove(LRUEntry entry, boolean removeFromPathCache) {
-        synchronized (cacheMonitor) {
-            if (removeFromPathCache) {
-                PathMap.Element element = entry.getElement();
-                remove(element);
-                element.remove();
-            } else {
-                idCache.remove(entry.getId());
-                entry.remove();
-            }
+        // assert: synchronized (cacheMonitor)
+        if (removeFromPathCache) {
+            PathMap.Element element = entry.getElement();
+            remove(element);
+            element.remove();
+        } else {
+            idCache.remove(entry.getId());
+            entry.remove();
         }
     }
 
@@ -554,19 +548,18 @@
      * @param removeFromPathCache whether to remove from path cache
      */
     private void evict(LRUEntry entry, boolean removeFromPathCache) {
-        synchronized (cacheMonitor) {
-            if (removeFromPathCache) {
-                PathMap.Element element = entry.getElement();
-                element.traverse(new PathMap.ElementVisitor() {
-                    public void elementVisited(PathMap.Element element) {
-                        evict((LRUEntry) element.get(), false);
-                    }
-                }, false);
-                element.remove(false);
-            } else {
-                idCache.remove(entry.getId());
-                entry.remove();
-            }
+        // assert: synchronized (cacheMonitor)
+        if (removeFromPathCache) {
+            PathMap.Element element = entry.getElement();
+            element.traverse(new PathMap.ElementVisitor() {
+                public void elementVisited(PathMap.Element element) {
+                    evict((LRUEntry) element.get(), false);
+                }
+            }, false);
+            element.remove(false);
+        } else {
+            idCache.remove(entry.getId());
+            entry.remove();
         }
     }
 
@@ -594,13 +587,12 @@
      * @param element path map element
      */
     private void remove(PathMap.Element element) {
-        synchronized (cacheMonitor) {
-            element.traverse(new PathMap.ElementVisitor() {
-                public void elementVisited(PathMap.Element element) {
-                    remove((LRUEntry) element.get(), false);
-                }
-            }, false);
-        }
+        // assert: synchronized (cacheMonitor)
+        element.traverse(new PathMap.ElementVisitor() {
+            public void elementVisited(PathMap.Element element) {
+                remove((LRUEntry) element.get(), false);
+            }
+        }, false);
     }
 
     /**



Mime
View raw message