difference between synchronizing a static method a

2019-01-13 05:54发布

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 synchronizing a method and synchronizing a block of code?

7条回答
Deceive 欺骗
2楼-- · 2019-01-13 06:49

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

查看更多
登录 后发表回答