difference between synchronizing a static method and a non static method

后端 未结 7 1360
一向
一向 2020-12-02 11:27

What is the difference between synchronizing a static method and a non static method in java?Can anybody please explain with an example. Also is there any difference in sync

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 12:13

    In short if you synchronize on a static method you will synchronize on the class (object) and not on an instance (object). That means while execution of a static method the whole class is blocked. So other static synchronized methods are also blocked.

提交回复
热议问题