[concurrency-interest] ConcurrentHashMap and null keys

Gregg Wonderly gregg at cytetech.com
Mon Apr 23 15:48:02 EDT 2007


I'm going though some classloader related code that currently uses a HashMap and 
'synchronized'.  This code has to make use of null keys because it uses return 
values from 'Thread.getContextClassLoader()' and 'ClassLoader.getParent()' as 
real contexts to deal with.  These values, can be null.  Currently 
ConcurrentHashMap doesn't support null keys.  I'd like to create less locking in 
some of this code by removing unnecessary synchronized use.  It's policy related 
code paths, so they are very frequently traveled execution paths in server 
software where multiple threads with different policies will be active.

What are good choices for managing this 'null' key issue?  Should I establish a 
'NULL' value for the times when the key is null?

Gregg Wonderly


More information about the Concurrency-interest mailing list