jhalterman / expiringmap

A high performance thread-safe map that expires entries
Apache License 2.0
1k stars 142 forks source link

Iterating of the map should not throw a ConcurrentModificationException #78

Closed bratkartoffel closed 9 months ago

bratkartoffel commented 2 years ago

Create a copy of the entries (guarded by a readLock) and iterate over that copy. This fixes #10 and maybe #30 (needs further testing though, couldn't reproduce that)

Create a copy of the underlying map and iterate over that, never throwing a ConcurrentModificationException. This comes with a small performance penalty though (copying the map content to new instance) but fixing the exception should have priority as this violates the contract of this class (threadsafe)

bratkartoffel commented 10 months ago

@jhalterman this PR is open for some time now, have you had time to look into this?

jhalterman commented 9 months ago

Thanks for this, and sorry for the huge delay. I don't love copying the map, but I agree with your point that thread safety is priority, so this is better than ConcurrentModificationException for now. I'll add a note about the copying behavior to the Javadoc and cut a new release.

jhalterman commented 9 months ago

This is released in 0.5.11.