difference between synchronizing a static method and a non static method

后端 未结 7 1366
一向
一向 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:16

    Dude, just a hint. Not related to your question:

    If any do*Stuff() methods does either

    this.a= /*yet another*/ new Object();
    

    or

    this.b= /*yet another*/ new Object();
    

    then you are screwed. Because the lock is inside the value, not inside the reference. See Java synchronized references

提交回复
热议问题