[JAVA concurrent programming practices] 1. Object sharing and java practices

Source: Internet
Author: User

[JAVA concurrent programming practices] 1. Object sharing and java practices
1. Stack closures

In stack closures, objects can only be accessed through local variables.

Stack blocking refers to limiting the Declaration and Application of variables to a local thread. The declarations and instantiated objects in this local thread are invisible to the outside of the thread, the stack of this local thread cannot be accessed by any other thread.

 

2. immutability

Immutable objects must be thread-safe.

 

 

3. Common Security release Modes

To securely publish an object, the object reference and object state must be visible to other threads at the same time.

1. Initialize an object reference in the static initialization function.

2. Save the object reference to a volatitle-type domain or AtomicReferance object.

3. Save the object reference to the final type domain of a correctly constructed object.

4. Save the object reference to a domain protected by the lock.

 

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.