[jboss-cvs] JBossAS SVN: r80096 - projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/cache/simple.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Oct 27 02:50:13 EDT 2008


Author: ALRubinger
Date: 2008-10-27 02:50:13 -0400 (Mon, 27 Oct 2008)
New Revision: 80096

Modified:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java
Log:
[EJBTHREE-1549] Synchronize on internal cacheMap to make a copy, freeing passivation to run after the lock is released

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java	2008-10-27 06:47:18 UTC (rev 80095)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java	2008-10-27 06:50:13 UTC (rev 80096)
@@ -51,7 +51,7 @@
    private Logger log = Logger.getLogger(SimpleStatefulCache.class);
 
    private StatefulContainer container;
-   private CacheMap cacheMap;
+   protected CacheMap cacheMap;
    private int maxSize = 1000;
    private StatefulSessionPersistenceManager pm;
    private long sessionTimeout = 300; // 5 minutes
@@ -71,6 +71,11 @@
       {
          super(maxSize, 0.75F, true);
       }
+      
+      public CacheMap(Map original)
+      {
+         super(original);
+      }
 
       public boolean removeEldestEntry(Map.Entry entry)
       {
@@ -193,12 +198,33 @@
             }
             try
             {
-               synchronized (cacheMap)
-               {                  
+               
+               /*
+                * EJBTHREE-1549
+                * 
+                * Passivation is potentially a long-running
+                * operation, so copy the contents quickly and 
+                * perform passivation on the unpublished 
+                * local stack variable copy
+                */
+               
+               // Initialize
+               CacheMap newMap = null;
+               
+               // Copy the contents of the internal map
+               synchronized(cacheMap)
+               {
+                  newMap = new CacheMap(cacheMap);
+               }
+               
+               /*
+                * End EJBTHREE-1549
+                */
+
                   if (!running) return;
                   
                   boolean trace = log.isTraceEnabled();
-                  Iterator it = cacheMap.entrySet().iterator();
+                  Iterator it = newMap.entrySet().iterator();
                   long now = System.currentTimeMillis();
                   while (it.hasNext())
                   {
@@ -236,13 +262,13 @@
                      }
                   }
                }
-            }
+            
             catch (Exception ex)
             {
                log.error("problem passivation thread", ex);
             }
-         }
       }
+      }
    }
 
    public void initialize(EJBContainer container) throws Exception




More information about the jboss-cvs-commits mailing list