Hashtable is thread safe for use by multiple reader threads and a single writing thread."> Hash...
1 Vector的方法都是同步的(Synchronized),是线程安全的(thread-safe),而ArrayList的方法不是,由于线程的同步必然要影响性能,因此,ArrayList的性能比Vector好。 2当Vector或ArrayList中的元素超过它的初始大小时,Vector会将它的容量翻倍,而ArrayList只增加50%的大小,这样,ArrayList就有利于节约内存空间。 HashMap通过hashcod...
另外一种方法就是使用lock语句,但要lock的不是HashTable,而是其SyncRoot;虽然不推荐这种方法,但效果一样的,因为源代码就是这样实现的: //Thread safe privatestaticSystem.Collections.Hashtable htCache =newSystem.Collections.Hashtable (); publicstaticvoidAccessCache () { lock( htCache.SyncRoot ) { htCach...
它是线程安全的,因为get、put、contains等方法都是同步的。此外,多个线程将无法同时访问哈希表,无论它...
If a thread-safe implementation is not needed, it is recommended to use HashMap in place of code Hashtable. If a thread-safe highly-concurrent implementation is desired, then it is recommended to use ConcurrentHashMap in place of code Hashtable. ...
If a thread-safe highly-concurrent implementation is desired, then it is recommended to use java.util.concurrent.ConcurrentHashMap in place of Hashtable.非线程安全情况下,推荐使用HashMap替代Hashtable;高并发线程安全情况下,推荐使用ConcurrentHashMap替代Hashtable。 Hashtable继承的Dictionary也被官方标定为...
Hashtable is thread safe for use by multiple threads. Dictionary public static members are thread safe, but any instance members are not guaranteed to be so. So Hashtable remains the 'standard' choice in this regard. Share Improve this answer Follow answered Aug 27, 2011 at 19:59...
FYI: In .NET, Hashtable is thread safe for use by multiple reader threads and a single writing thread, while in Dictionary public static members are thread safe, but any instance members are not guaranteed to be thread safe. We had to change all our Dictionaries back to Hashtable because ...
Vector and Hashtable are two collection classes that are inherently thread safe or synchronized; whereas, the classes ArrayList and HashMap are unsynchronized and must be `wrapped` via Collections.SynchronizedList or Collections.synchronizedMap if synchronization is desired. Vector和Hashtable是线程安全的,...
//Thread safe private static System.Collections.Hashtable htCache = new System.Collections.Hashtable (); public static void AccessCache () { lock ( htCache.SyncRoot ) { htCache.Add ( "key", "value" ); //Be careful: don't use foreach to operation on the whole collection ...