Whether a static method is used in multi-threading is a thread-safe issue

Source: Internet
Author: User

The members of a class are divided into two classes, static members (static member), and instance members (instance member). A static member belongs to a class and an instance member is an instance of an object, that is, a class.

A brief discussion of whether static fields and static methods are used in a class is a thread-safe issue.

We are aware that the call to static field and static method is called through the class. Static methods do not operate on specific instances, only static members. Instance methods can operate on specific instances, access static members, and access instance members.

So, is the static method used in multi-threading a thread-safe issue? This depends on whether static methods are used in static methods to see if static members are employed.

Because, when using the same static method in multi-threading, each thread uses a copy of its own instance field (instance field) and shares a static field. So, if the static method does not manipulate a static member, only the instance fields (instance field) are used inside the method, which does not cause security problems. However, if the static method operates on a static field, it needs to be handled securely in a static method with mutually exclusive access.

http://blog.csdn.net/scucj/article/details/1394523

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.