AW: [concurrency-interest] Re: Question about Hashtable andConcurrentHashMap.

Ernst, Matthias matthias.ernst@coremedia.com
Thu, 7 Oct 2004 09:08:48 +0200


Paul: 
> However, the following I am not sure is a reason... Surely 
> though the concurrent classes would not break the following? 
> I mean, one can argue about the style if desired, but 
> replacing Hashtable with ConcurrentHashMap should not break 
> this code? Or is there something really fundamental that I am missing?
> 
> > Also, it's not uncommon for Java programmers to "synchronize" the 
> > hashtable object when they want to temp. lock the hashtable:
> >
> >   synchronized (hashtable) {
> >     hashtable.get ...
> >     hashtable.put ...
> >     // etc
> >   }

There may be other code that does, say, a put without synchronization,
_knowing_, that all hashtable operations are synchronized on the table
object. ConcurrentHashMap would break that contract. So a put could slip
in between the two operations up there.


Matthias