commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <scolebou...@btopenworld.com>
Subject Re: [Collections] SoftRefHashMap.purge throws ConcurrentModificationException
Date Sun, 24 Nov 2002 17:34:01 GMT
I have applied the suggested fix, as it appears to be sensible, thanks.

However, we now advise using ReferenceMap instead of SoftRefHashMap, as the
latter is severly broken.

Stephen

----- Original Message -----
From: "Eduardo Francos" <efrancosos@incontext.fr>
> I'm using the SoftRefHashMap to manage images and I get a
> ConcurrentModificationException when I call the purge method.
> Looking at the code I found that the method removes GCed references
> directly from the Map instead of using the iterator's remove method.
> I subclassed SoftRefHashMap and implemented the following change in
> purge that works.
>
> 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) {
>             // Fix for ConcurrentModificationException
>             // Previously:
>             // map.remove( key );
>             i.remove();
>             // end ConcurrentModificationException fix
>         }
>     }
> }
>
> Either I was doing something wrong or the fix is required.
>
> Eduardo
>
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:commons-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:commons-user-help@jakarta.apache.org>
>


--
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