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: [email protected]
For additional commands, e-mail: [email protected]