You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2010/03/31 14:43:04 UTC

svn commit: r929506 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java

Author: jukka
Date: Wed Mar 31 12:43:03 2010
New Revision: 929506

URL: http://svn.apache.org/viewvc?rev=929506&view=rev
Log:
JCR-2546: SISM blocks the item state cache when loading a new item

Synchronize only when a cache miss occurs.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?rev=929506&r1=929505&r2=929506&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java Wed Mar 31 12:43:03 2010
@@ -1351,20 +1351,28 @@ public class SharedItemStateManager
 
     /**
      * Returns the item state for the given id without considering virtual
-     * item state providers. This method is synchronized to ensure that
-     * a cache entry is not created twice.
+     * item state providers.
      */
-    private synchronized ItemState getNonVirtualItemState(ItemId id)
+    private ItemState getNonVirtualItemState(ItemId id)
             throws NoSuchItemStateException, ItemStateException {
         ItemState state = cache.retrieve(id);
         if (state == null) {
-            // not found in cache, load from persistent storage
-            state = loadItemState(id);
-            state.setStatus(ItemState.STATUS_EXISTING);
-            // put it in cache
-            cache.cache(state);
-            // set parent container
-            state.setContainer(this);
+            synchronized (this) {
+                // Use a double check to ensure that the cache entry is
+                // not created twice. We don't synchronize the entire
+                // method to allow the first cache retrieval to proceed
+                // even when another thread is loading a new item state.
+                state = cache.retrieve(id);
+                if (state == null) {
+                    // not found in cache, load from persistent storage
+                    state = loadItemState(id);
+                    state.setStatus(ItemState.STATUS_EXISTING);
+                    // put it in cache
+                    cache.cache(state);
+                    // set parent container
+                    state.setContainer(this);
+                }
+            }
         }
         return state;
     }