扫描结果不一定是圣旨,但可借此机会了解清楚具体在什么场景使用什么集合类,什么时候配合使用同步块,考虑线程安全的情况下使用ConcurrentHashMap是可以的。
Synchronized classes Vector, Hashtable, Stack and StringBuffer should not be used
Early classes of the Java API, such as Vector
, Hashtable
and StringBuffer
, were synchronized to make them thread-safe. Unfortunately, synchronization has a big negative impact on performance, even when using these collections from a single thread.
It is better to use their new unsynchronized replacements:
ArrayList
orLinkedList
instead ofVector
Deque
instead ofStack
HashMap
instead ofHashtable
StringBuilder
instead ofStringBuffer
Noncompliant Code Example
Vector cats = new Vector();
Compliant Solution
ArrayList cats = new ArrayList();