Fast background I have a parallel map that I used to cache some values that change frequently (it’s worth caching them all the same when testing). I want to regularly export items from my cache, checking the expiration time. I use the keySet () method to get a link to all my keys, then check the values and, if expired, I delete them. In other threads, the cache is requested and updated (deleted) constantly.
From the javadocs for keySet (), he mentions if the map has changed when I repeat over a set of keys. Set the results to undefined. Obviously, I would like to have some way to handle this so that the results are valid. Would it be enough to pass Set to a HashSet and then iterate over this set, since I understand that this set will not be supported by the card, is this a waste of memory? Any ideas appreciated.
Unfortunately, my evictor is not the only way to remove elements from a parallel map, so I correctly say that I need to copy keySet to another set before iterating through it.
Thanks in advance
EDIT: Turns out I read javadocs for the Map keySet () method instead of ConcurrentMap keySet (). Thank you, my bad :)
Returns the given representation of the keys contained in this map. The set is reinforced by the map, so changes to the cards are reflected in the set, and vice versa. If the map is changed while the iteration over the set is in progress (except for the iterator to independently delete the operation), the results of the iteration are undefined. The set supports the delete element, which removes the corresponding display from the display, through Iterator.remove, Set.remove, removeAll retainAll, and clear operations. It does not support add or addAll.
java concurrency map
Paul whelan
source share