synchronized static 方法和 instance 方法的区别

解决方案 »

  1.   

    synchronized static方法 就是同步的静态方法,只要类装载器装载了相应的类,就可以同步执行该方法。instance 方法 依赖于某个具体对象的方法,只有该对象被创建,才能执行,否则会 throw NoPointException
      

  2.   

    difference betweennclass A {
         synchronized static methodA(){
            //something
         }
         synchronized methodB(){ 
            //something
         }
    }
    in another way to help you comprehendclass A {
         static methodA(){
            synchronized (A.class){
              //something
            }
         }
         methodB(){ 
            synchronized(this){
            //something
            }
         }
    }