java synchronized static method and common method

下面的鎖是不一樣的。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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章