How does static code run with multiple threads?

后端 未结 6 926
青春惊慌失措
青春惊慌失措 2021-01-04 06:38

I was reading Threading from within a class with static and non-static methods and I am in a similar situation.

I have a static method that pulls data from a resourc

6条回答
  •  盖世英雄少女心
    2021-01-04 07:10

    You should distinguish between static methods and static fields in this case. Each call to a static method will have its own "copy" of the method and its local variables. That means that in your sample, each call will operate on its own MyObject instance, and the calls will have nothing to do with each other. This also means that there is no problem with executing them on different threads.

提交回复
热议问题