commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Renè Glanzer <>
Subject [collections] LRUMap Problem ConcurrentModificationException
Date Tue, 09 Jun 2009 16:33:12 GMT

I us a LRUMap for caching search results from the database. To limit
the maximum number of searches cached i store them in a LRUMap. Also
the timestamp when the entry was put to the map is stored.
Additionally to the maximum number of the LRUMap i also implemented a
thread which periodicly checks the age of the entries and deletes them
when they are too old.

For this i generated an Iterator which delivers me each entry and if
the creation date is too old i call iterator.remove().
But exactly on this line i get an
"java.util.ConcurrentModificationException" although i wrapped all
access to the map with synchronized blocks. So every put and get
methods are synchronized.

Here is the code block which should delete old entries:

store: is the LRUMap
birth: is a long which keeps the creation time when this is set to 0
the item should be deleted

public void removeAllExpiredItems()
        Object o=this.get(key);
        if(o != null)
          Item iEntry=(Item);
            it.remove(); //Here the exception occurs
      this.setLastCleanDate(new Date()); //only to know when the
deleter run the last time

Somebody able to help me?
Thank with regards

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message