commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Dunning <ted.dunn...@gmail.com>
Subject Re: [collections] LRUMap Problem ConcurrentModificationException
Date Tue, 09 Jun 2009 17:39:23 GMT
I apologize for not reading your thread with great care, but I think that
your problem is pretty clear.

The issue is not to do with gets and puts overlapping.  The issue is that a
put or remove happened during the life of your iterator.

One way to avoid this is to synchronize the entire method that does the
deletion of old elements.  To speed that up, you might just synchronize the
scan for elements to delete and collect them into a list.  Then you can
delete them outside the loop.  Since your scan is probably pretty fast, this
may be sufficient.  With very high levels of updates and threading, it would
cause problems.

Another option is to clone the table.  I believe that some implementations
of LRUMap in Lucene do copy-on-write semantics, but I don't think that
collections has these.  Without that, cloning will be as slow or slower than
your scan so the first option would be better.

I am curious, however, why you didn't make use of the built-in capabilities
of the LRUMap to help you with this.  Notably, you should probably just
over-ride the removeLRU(Entry) method and set the scanUntilRemovable flag.
I think that this would take the place of your loop and would be much more
efficient.

On Tue, Jun 9, 2009 at 9:33 AM, Renè Glanzer <rene.glanzer@gmail.com> wrote:

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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message