How do you synchronize a block of code inside a method?

Last Updated :
Discuss
Comments

How do you synchronize a block of code inside a method?

lock(this)

synchronize(this)

synchronized(this) { /* code */ }

Thread.lock(this) {}

Share your thoughts in the comments