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

  • 相关阅读:
    深入剖析Java中的装箱和拆箱
    JDBC(1)
    设计模式
    MySQL学习笔记(3)
    MySQL学习笔记(2)
    MySQL学习笔记(1)
    tomcat 部署项目出现Error thrown in preDeregister method
    JSP页面中的request.getContextPath()出现“ .... .. refers to the missing type String
    myEclipse 导入 jquery包为什么整个项目都会报错
    走楼梯
  • 原文地址:https://www.cnblogs.com/lwhkdash/p/2872366.html
Copyright © 2011-2022 走看看