Usage of synchronized in Java

Source: Internet
Author: User

Turn from: Original: http://blog.csdn.net/luoweifu/article/details/46613015
Author: Luoweifu

Synchronized is a key word in Java and is a synchronous lock. It modifies objects in the following ways:
1. Modify a code block, the modified code block is called the synchronous statement block, its scope is the curly braces {} In the code, the object is to call the object of this block of code;
2. Modify a method, the modified method is called the synchronous method, its scope is the whole method, the object is to call the object of this method;
3. Modify a static method whose scope of action is the entire static method, and the object of the action is all objects of this class;
4. Modify a class whose scope of action is synchronized the part enclosed in parentheses, and the object of the principal is all objects of the class.

Usage of synchronized in Java

Related Article

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.