Java thread-safe collection object and java thread set

Source: Internet
Author: User

Java thread-safe collection object and java thread set

Vector and ArrayList

Vector is thread-safe, but Vector is not used in most cases, because thread security requires greater system overhead.


HashTable and HashMap

Methods In Hashtable are synchronized, while those in HashMap are not synchronized by default. Hashtable can be used directly in a multi-thread concurrent environment, but you need to add synchronization to use HashMap.


StringBuilder and StringBuffer

The StringBuilder and StringBuffer methods are the same, that is, the former is multithreading while the latter is single-threaded.


Stack inherited from Vector is also thread-safe.


By using java. util. collections to create a thread-safe set, such as Connections. synchronizedSet (Set <T>); Connections. synchronizedList (List <T>); Connections. synchronizedMap (Map <K, V>). The simple principle is that synchronized is added to every method to ensure thread security.



It may not be complete.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.