Instance methods and thread-safety of instance variables

前端 未结 6 744
Happy的楠姐
Happy的楠姐 2021-01-30 23:40

I would like to known if each instance of a class has its own copy of the methods in that class?

Lets say, I have following class MyClass:

p         


        
6条回答
  •  离开以前
    2021-01-31 00:05

    A method is nothing but a set of instructions. Whichever thread calls the method, get a copy of those instructions. After that the execution begins. The method may use local variables which are method and thread-scoped, or it may use shared resources, like static resources, shared objects or other resources, which are visible across threads.

提交回复
热议问题