Vector, ArrayList, HashTable, HashMap哪些是线程安全的?哪些不是?

2009年09月03日 01:21 阅读 17 Java

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是线程安全的,ArrayList和HashMap不是线程安全的而且必须要通过Collections.SynchronizedList或者Collections.synchronizedMap来包装一下才能实现同步。

还没有评论!