[concurrency-interest] Re: Question about Hashtable and ConcurrentHashMap.

Joe Bowbeer jozart@blarg.net
Wed, 6 Oct 2004 23:22:52 -0700


I successfully waged a campaign against a drop-in replacement.

My campaign was based on fear.

Fear that replacing "synchronized" Hashtable with ConcurrentHashMap would 
break the 1000's of synchronized Hashtable subclasses in subtle ways.

For example, googling for ["extends Hashtable" + synchronized] turns up over 
300 hits.  I estimate there must be at least 100x that many beyond google's 
reach.

Some instances on the web follow.  They all add and/or override 
synchronized" methods.

http://www.acme.com/java/software/Acme.LruHashtable.html

CacheTable class in this JavaWorld article:
http://www.javaworld.com/javaworld/jw-06-1999/jw-06-cooltools.html

http://www.cs.cornell.edu/home/bba/doc/JavaGroups.DistributedHashtable.html

http://www-sldnt.slac.stanford.edu/jas/help/current/api/jas/jas.util.OrderedHashtable.html

http://www.cs.man.ac.uk/~alanw/CS3111/Examples/Lecture9-Examples/CountServer.java

http://www.novocode.de/prod/nf/manual/doc/api/novocode.netforge.http.filter.FilterManager.html

http://www.novocode.de/prod/nf/manual/doc/api/novocode.netforge.backend.BackendManager.html

http://www.roguewave.com/support/docs/hppdocs/tprapi/com.roguewave.tools.v2-0.HashDictionary.html


Here are some examples in Sun's code:

http://java.sun.com/j2se/1.4.1/docs/api/java/util/Properties.html

Note synchronized (this)
http://java.sun.com/j2se/1.4.1/docs/api/javax/swing/UIDefaults.html

Also see repositoryidcache*.java in com.sun.corba.se.internal.util and 
orbutil


Furthermore, a google for "extends Properties" + "synchronized" turns up 
many more:

This one, for example:

  http://www.w3.org/Jigsaw/User/api/w3c.util.ObservableProperties.html

And then there's java.security.Provider (abstract) and all of its 
subclasses:

  http://java.sun.com/j2se/1.4.1/docs/api/java/security/Provider.html


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
  }

A lot of this code was written by early adopters (gotta love 'em), and a lot 
of this code is still running today.



----- Original Message ----- 
From: "Martin Buchholz" <Martin.Buchholz@Sun.COM>
To: <Bino.George@Sun.COM>; <concurrency-interest@altair.cs.oswego.edu>
Cc: <tl-dev@Sun.COM>; <Kenneth.Russell@Sun.COM>; <Jeannette.Hung@Sun.COM>
Sent: Wednesday, October 06, 2004 10:16 PM
Subject: [concurrency-interest] Re: Question about Hashtable and 
ConcurrentHashMap.


Bino, I've taken the liberty of forwarding your question to the
Experts.

In my opinion... they are not compatible *enough*, and the
performance advantage is probably only significant when
concurrency is high.

Martin

Bino George wrote:
> Hi Folks,
>           I have been reading that ConcurrentHashMap is compatible
> with Hashtable and is mush faster than Hashtable. So is there any reason
> why we could not replace the implementation of Hashtable with that of
> ConcurrentHashMap ? Obviously there must be a reason why it was not
> done ? Can you tell me what the reason is ?
>
> Thanks,
> Bino.
>


_______________________________________________
Concurrency-interest mailing list
Concurrency-interest@altair.cs.oswego.edu
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest