commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Yu <j...@scioworks.com>
Subject [PATCH][collections] SoftRefHashMap
Date Wed, 17 Apr 2002 07:57:22 GMT
The purge() method causes ConcurrentModificationException as it uses 
map.remove() in the middle of iteration. I've changed it to use 
Iterator.remove()

     public void purge() {
         Map map = getMap();
         Set keys = map.keySet();
         if ( keys == null ) {
             return;
         }
         for ( Iterator i = keys.iterator(); i.hasNext(); ) {
             Object key = (Object) i.next();
             Reference ref = (Reference) map.get( key );
             if ( ref.get() == null ) {
                 i.remove();       // <-- Modified line
             }
         }
     }

Besides, I have a modified SoftRefHashMap version which does more efficient 
purging by using the java.lang.ref.ReferenceQueue, similar to what 
java.util.WeakHashMap does. Should I post the modification to the mailing list?

-- 
John Yu                       Scioworks Technologies
e: john@scioworks.com         w: +(65) 873 5989
w: http://www.scioworks.com   m: +(65) 9782 9610

Scioworks Camino - "Rapid WebApp Assembly for Struts"


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message