jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r929506 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Date Wed, 31 Mar 2010 12:43:04 GMT
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;
     }



Mime
View raw message