java synchronized static method and common method

来源:互联网 发布:php argv 编辑:程序博客网 时间:2024/06/01 22:34

下面的锁是不一样的。static,是相当于锁类;二非static是锁类的一个实例,即this.

  •  public static synchronized void abc(int threadNo) {   
  • 19         for (int i = 1; i < 10000; i++) {   
  • 20               
  • 21                 System.out.println("No." + threadNo + ":" + i);           
  • 22         }   
  • 23     } 


  •  public synchronized void abc(int threadNo) {   
  • 19         for (int i = 1; i < 10000; i++) {   
  • 20               
  • 21                 System.out.println("No." + threadNo + ":" + i);           
  • 22         }   
  • 23     } 

     



    http://blog.csdn.net/yangzhijun_cau/article/details/6432216