1 Reply Latest reply on Mar 22, 2006 7:51 AM by Adrian Brock

    JBAS-2989 - DRM and iterator

    Adrian Brock Master

      Further to this bug report:
      http://jira.jboss.com/jira/browse/JBAS-2989

      Is there really any need to clone the concurrent hashmap?

      
       HashMap localReplicants;
       synchronized (this.localReplicants)
       {
       localReplicants = new HashMap(this.localReplicants);
       }
      
       Iterator entries = localReplicants.entrySet().iterator();
       while( entries.hasNext() )
       {
       Map.Entry entry = (Map.Entry) entries.next();
       String key = (String) entry.getKey();
       Object replicant = entry.getValue();
      


      It serves no purpose to my mind.

        • 1. Re: JBAS-2989 - DRM and iterator
          Adrian Brock Master

          Similarly, why does JBossCacheManager clone the concurrent map,
          get an entry set and then only use the key?

           protected void clearSessions()
          
          ...
          
           // Next, the local copy of the distributed cache
           Map unloaded = new HashMap(unloadedSessions_);
           Set entries = unloaded.entrySet();
           for (Iterator it = entries.iterator(); it.hasNext(); )
           {
           Map.Entry entry = (Map.Entry) it.next();
           String realId = (String) entry.getKey();
           proxy_.removeSessionLocal(realId);
           unloadedSessions_.remove(realId);
           }