You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by John Yu <jo...@scioworks.com> on 2002/04/17 09:57:22 UTC
[PATCH][collections] SoftRefHashMap
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: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: [PATCH][collections] SoftRefHashMap
Posted by Juozas Baliuka <ba...@mwm.lt>.
Hi,
Yes "purge()" method must be fixed this way and I think it must be private.
> 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:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>