Synchronized lock common method and lock static method

Source: Internet
Author: User

1. Object lock key Only one can be mutually exclusive, in order to guarantee the uniqueness of shared variables

2. In the static method of the lock, and the instance method on the lock, the default is not the same, if the synchronization needs to make two locks.

3. The lock on a method of the same class comes from the object that called the method, and if the object calling the method is the same, then the lock must be the same, otherwise it will be different. For example, new A (). x () and new A (). x (), the object is different, the lock is different, if a's simple interest, it can be mutually exclusive.

4. Static method lock, can be locked with all other static methods of mutual exclusion

5. Static method lock, and Xx.class lock effect, directly belongs to the class

Reprint: http://greemranqq.iteye.com/blog/1974143

Synchronized lock common method and lock static method

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.