commons-user mailing list archives

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

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()
  {
    synchronized(this.store)
    {
      Iterator it=this.store.keySet().iterator();
      while(it.hasNext())
      {
        Object key=it.next();
        Object o=this.get(key);
        if(o != null)
        {
          Item iEntry=(Item)this.store.get(key);
          if(iEntry.birth==0)
            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
René

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message