zoukankan      html  css  js  c++  java
  • Will static methods over multithreading cause threadsafe problem?

      Most of the time when we are using multi-threading we are likely facing the thread-safe issue,it seems that this problem always come up with calling static methods or functions in a thread when multi-threading coding.But is it correct? For more detail, i've done a lot google to search this issue in detail.

      After reading some helpful blogs and tech articles,i find out that static method or function is not the key or the cause of the thread-safe problem.In fact what i thought about thread-safe problem is even wrong. The most important thing to this issue is whether one or more static variables are being used in any single thread in multi-thread coding because only static resources and global variables are shared by threads.If no static variables or static fields are occupied in static methods or functions in these thread,we don't need to worry about the synchro of these static variables or static fields.Be clear that instance variables and fields(including properties of course)  aren't shared by different thread,they only belong to the thread which called the static method or function declaring them.

      So,let's make it more brief:

        1.If no static resources or global variables are used in a static method/function, we are not facing the thread-saft problem,even if we are using multi-thread technology.

        2.If any instance variable is declared in a static method/function,this variable only belongs to the thread which call this static method/function.

        See also:

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

  • 相关阅读:
    Django框架 之 logging配置
    Django框架 之 中间件
    Django框架 之 form组件
    Django框架 之 Ajax
    Django框架 之 Pagination分页实现
    3张图带你看懂扩展KMP(EXKMP)
    [TJOI2018]游园会(状压dp+LCS)
    [BZOJ 2959] 长跑(LCT+并查集)
    [NAIPC2016]Jewel Thief(决策单调性+分治)
    [BZOJ 1563] [NOI 2009] 诗人小G(决策单调性)
  • 原文地址:https://www.cnblogs.com/lwhkdash/p/2872366.html
Copyright © 2011-2022 走看看