Synchronous security Collection, it is safe to use this map in multithreading, but what does this security mean? Not to say that now 2 threads to use this map, the result of this map I do not have to add synchronize synchronization lock, not so, multi-threaded or to add this synchronization lock, because the map itself is not the security of thread security, when the map value is a Vo object, And this object in the multi-threaded changes, or need to synchronize lock, and map itself is the thread security is the ability to delete the element in the map traversal, modify can, but delete some map can be not, No, map deletion must be error: Java.util.ConcurrentModificationException, this is because HASHMAP, list and other collections are unsafe collections, traversal can not be deleted, and Concurrenthashmap is a multi-threaded security map collection that can be deleted when traversed. As to why can not be deleted because HashMap, list and so on is traversed through the itator, and its time is the element is irreversible, and the yoke, when it is a delete, such as the synchronization of external list or HashMap when not found The corresponding elements in the list or HashMap will be error-related. That unsafe collection when to use, one is single-threaded under can be used, but still can not be deleted all over the time, but also one is such as the base template encapsulation collection, this collection will only get not deleted, this situation can choose the non-synchronous security collection. So whether single-threaded or multi-threaded, it is almost always best to use a thread-safe collection (a collection that is only used for get is not deleted except that it can be used in a non-secure collection, such as a collection of game-based data).
Concurrenthashmap the true meaning of synchronous security (Stringbuff is synchronous and secure, stringbutter unsafe)