[jboss-cvs] JBossAS SVN: r60349 - branches/Branch_4_0/tomcat/src/main/org/jboss/web/tomcat/tc5/session.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 6 17:32:01 EST 2007


Author: bstansberry at jboss.com
Date: 2007-02-06 17:32:01 -0500 (Tue, 06 Feb 2007)
New Revision: 60349

Modified:
   branches/Branch_4_0/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheManager.java
Log:
[JBAS-4075] Copy off the EDU ConcurrentHashMap before toArray call

Modified: branches/Branch_4_0/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheManager.java
===================================================================
--- branches/Branch_4_0/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheManager.java	2007-02-06 22:22:56 UTC (rev 60348)
+++ branches/Branch_4_0/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheManager.java	2007-02-06 22:32:01 UTC (rev 60349)
@@ -21,6 +21,7 @@
  */
 package org.jboss.web.tomcat.tc5.session;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
@@ -846,9 +847,19 @@
     */
    public ClusteredSession[] findLocalSessions()
    {
+      // JBAS-4075 -- ConcurrentHashMap.values().toArray() isn't thread
+      // safe, so we have to copy off the collection using its iterator
+      // Can't use the ArrayList c'tor or addAll, as those use toArray
+      // behind the scenes
       Collection coll = sessions_.values();
-      ClusteredSession[] sess = new ClusteredSession[coll.size()];
-      sess = (ClusteredSession[]) coll.toArray(sess);
+      ArrayList list = new ArrayList(coll.size());
+      for (Iterator it = coll.iterator(); it.hasNext(); )
+      {
+         list.add(it.next());
+      }
+      
+      ClusteredSession[] sess = new ClusteredSession[list.size()];
+      sess = (ClusteredSession[]) list.toArray(sess);
       return sess;
    }
 




More information about the jboss-cvs-commits mailing list