您的位置:首页 > 编程语言 > Java开发

Java - 提高-源码(5) - HashTable(未详解)

2017-07-05 21:59 435 查看
HashTable源码解析

源码对应JDK1.7

JDK1.7源码下载地址:JDK1.7下载地址

这里不打算讲解HashTable的源码了,从操作上来说,HashTable是差不多的。

从使用率上来说,HashTable使用的太少了..

在源码的注释中是这样描述的:

Java Collections Framework.
Unlike the new collection Implementations, {@code Hashtable} is synchronized.
If a Thread-safe implementation is not needed, it is recommended to use {@link HashMap} in place of {@code Hashtable}.
If a thread-safe Highly-concurrent implementation is desired, then it is recommended To use {@link java.util.concurrent.ConcurrentHashMap} in place of {@code Hashtable}.
大意是:

Java集合框架。

与新集合“实现”不同,{@code Hashtable}已同步。

如果不需要Thread-safe实现,建议使用{@link HashMap}代替{@code Hashtable}。

如果需要线程安全的高度并发实现,那么建议使用{@link java.util.concurrent.ConcurrentHashMap}代替{@code Hashtable}。

因为赶时间,打算将HashTable的源码解析延后,等什么时候闲下来再写吧。

下面说说HashTable 和HashMap的区别。

HashMap 和 HashTable的区别

HashMap允许key,value为null  ;  HashTable不允许key,value为null。

HashMap默认初始容量为16  ;  HashTable默认初始容量为11.

HashMap非线程安全  ;  HashTable线程安全(所有的public方法都是synchronized)

HashMap继承于AbstractMap  ;  HashTable继承于Dictionary
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: