java併發:Synchronized 原理

1.同步代碼塊:   反編譯結果:      monitorenter : 每個對象有一個監視器鎖(monitor)。當monitor被佔用時就會處於鎖定狀態,線程執行monitorenter指令時嘗試獲取monitor的所有權,過程如下: 1、如果monitor的進入數爲0,則該線程進入monitor,然後將進入數設置爲1,該線程即爲monitor的所有者。 2、如果線程已經佔有該monitor
相關文章
相關標籤/搜索