Pure Danger Tech


ConcurrentReferenceHashMap in Java 7?

17 Apr 2008

There is an interesting proposal under discussion on the concurrency-interest mailing list to add a ConcurrentReferenceHashMap as part of JSR 166. The ConcurrentReferenceHashMap would be a combination of a concurrent map (like ConcurrentHashMap), with optional reference (like IdentityHashMap) or equality semantics, and with strong, weak, or soft keys and values (partially covered by WeakHashMap). I actually had the need recently for a concurrent, identity-based, weak hash map right now so this would have fit the bill perfectly.

The Google Collections Library has a similar animal in ReferenceMap which is concurrent, allows choosing the reference type (including phantom references), but uses equality for strong references and identity for the rest.

The proposal is being made by Jason Greene from Red Hat and you can peruse the initial source code and join the concurrency mailing list if you want to give comments.