Race Condition with Static Class?

后端 未结 3 1653
孤独总比滥情好
孤独总比滥情好 2020-12-06 07:52

Let\'s say I have a static class with a static method.

Multiple threads can call this static method concurrently.

Is there a potential for a race condition u

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-06 08:24

    A - No. Race conditions only occur when static methods are attempting to access a shared resource. The local variable will be unique to each thread calling the method.

    B - Yes. Those static members will be shared by all of the threads calling that method.

提交回复
热议问题