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

  • 相关阅读:
    Golang关键字—— var
    Ubuntu下搭建Golang开发环境
    CentOS安装MongoDB
    使用2-3法则设计分布式数据访问层
    8 种提升 ASP.NET Web API 性能的方法
    MongoDB 聚合之 MapReduce
    常用开源项目及工具汇总——持续更新
    了解一下jsp
    前苹果副总裁:如果你做的事情毫不费力,就是在浪费时间
    思考
  • 原文地址:https://www.cnblogs.com/lwhkdash/p/2872366.html
Copyright © 2011-2022 走看看