Those classes in the Java collection are thread-safe

Source: Internet
Author: User
Tags stringbuffer

Thread-Safe classes

In the collection framework, some of the classes are thread-safe, and these are all occurrences of jdk1.1. After the jdk1.2, there are many non-thread-safe classes. The following are the thread-safe classes of synchronization:

Vector: It's more of a synchronization mechanism (thread-safe) than ArrayList, because it's less efficient and it's not recommended anymore. In the Web application, especially the foreground page, the efficiency (page response speed) is often preferred.

STATCK: Stack class, advanced post-out

Hashtable: It's a thread-safe more than HashMap.

Enumeration: enumeration, equivalent to an iterator

In addition to these, the others are non-thread-safe classes and interfaces.

Thread-safe classes whose methods are synchronous, can only have one access at a time. is a heavyweight object with low efficiency.

Other:

1. The difference between Hashtable and HashMap

Hashtable is thread-safe, that is, the Hashtable method provides a synchronization mechanism, HASHMAP is not thread-safe, that is, does not provide a synchronization mechanism; Hashtable does not allow null values to be inserted, hashmap allow!

2. How to modify a collection with multithreading concurrency

With the old Vector/hashtable class

StringBuffer is thread safe, and StringBuilder is thread insecure. For security and insecurity without deep understanding of the situation, it is easy to create such an illusion, if the operation of StringBuffer is thread-safe.

Those classes in the Java collection are thread-safe

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.