Java Concurrency Programming Combat: Note one

Source: Internet
Author: User

1, if more than one thread accesses the same mutable state variable when not using the appropriate synchronization, then the program will be an error, there are three ways to fix the problem:

  • This state variable is not shared between threads.
  • Modify the state variable to a variable that is immutable.
  • use synchronization when accessing state variables.

2. What is thread-safe?

  • This class is thread-safe when multiple threads access a class, regardless of how the runtime environment is scheduled or how those threads will be executed alternately, and if no additional synchronization or collaboration is required in the keynote code, and the class behaves correctly.
  • Simpler definition: When multiple threads access a class, the class always shows the correct behavior, then it is called a thread-safe class.

3, the thread security class encapsulates the necessary synchronization mechanism, so the client does not need to take further synchronization measures.

4.




Java Concurrency Programming Combat: Note one

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.