synchronized同步三種使用方法

1.同步代碼塊 synchronized (對象){ //代碼塊 }上面的對象能夠是任意對象,但必須爲同一對象 2.同步函數 synchronized void method(){ //代碼 }同步方法使用的同步對象爲該方法所屬類自己,即this 3.同步靜態方法 synchronized static void method(){ //代碼 }靜態同步方法使用的鎖是類的
相關文章
相關標籤/搜索