Reputation: 322
As far as I know ConcurrentHashMap partitions the buckets and has separate locks on each partition. But the HashTable has one single lock for all buckets.
As a result the ConcurrentHashMap can be either more efficient or (in worst case )equally efficient as HashTable. So why does Java needs to keep HashTable in its latest versions.
Isn't HashTable obselete now? Or are there still some pros HashTable has over ConcurrentHashMap?
Upvotes: 2
Views: 333
Reputation: 22442
This concept is NOT only applicable for Hashtable
, in fact it is applicable for all legacy classes, as Java versions are expected to be binary backwards-compatible.
This will be really helpful for the applications or projects wanted to upgrade to the newer versions of Java without worrying about modifying their existing functionality, which use some legacy classes (like Hashtable
, Vector
, etc..).
Backward Compatibility
Java versions are expected to be binary backwards-compatible. For example, JDK 8 can run code compiled by JDK 7 or JDK 6. It is common to see applications leverage this backwards compatibility by using components built by different Java version. A Compatibility Guide (explained later) exists for each major release to provide special mention when something is not backwards compatible.
You can look at here
Upvotes: 1
Reputation: 140525
A very simple reason: there might be zillions of lines of code using that classic. And people that would like to recompile that code using a newer JDK.
You want to break all of them!?
Upvotes: 5