On 09/06/10 15:56, tsuna wrote:
Oh, I see.  But that's because the regionCachePrefetchEnabled method
was unnecessarily changing the Map.  If the "read-only" methods like
this one weren't modifying any data structure (and they don't need
to), this problem wouldn't exist.

Yep, exactly. None of the other 3 ways need additional synchronization, it's just the one specific way it was implemented (hence my 'won't work, as it's written' originally).

Also even though ConcurrentHashSet doesn't exist, it can be
implemented by storing some random, unique Object instance as the
value.  I think that's how HashSet is implemented:

Yeah, it's very easily implemented. In fact, there's a utility method to do this easily (which I only just learned about a little while ago, after sending the original email -- there's always something new to learn!):

  Collections.newSetFromMap(new ConcurrentHashMap());

which would work correctly in this instance. As I said though, if it's a write-rarely, read-frequently, low-number-of-entries scenario then CopyOnWriteArraySet will likely work just as well, if not better.

Cheers,

Paul

Reply via email to