Multiple Threads: Thread safety

Source: Internet
Author: User

Thread safety means that there are no race conditions that allow multiple threads to execute at the same time, and the execution of the resulting idempotent blocks.

Java code Secure resources in multithreaded environments:

1, the basic data type of local variables;

2. A local variable of a non-basic data type that is not a return value and is not passed to a method accessed by another thread;

3. Subject to thread control and no escaping resources;

4, the shared state itself is a synchronized resource.

Thread control escape means that the creation, use, and destruction of resources are in the same thread and are never out of control of the thread.

Unsafe resources:

1, the Java class object member variable;

2, the sharing state is not synchronized;

3. Generate thread control to escape the resources;

4. The reference to the object is not thread-safe, even if it is an immutable object.

Multiple Threads: Thread safety

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.