0

If I always call a method from a synchronised block then what is advantage of making any method as synchronized?

Thanks in advance.

user1147070
  • 491
  • 7
  • 21

1 Answers1

1

It's just another way of writing the same thing. If your synchronized block exactly matches a method block, then it's just easier to read that way. Syntax sugar.

Which is easier?

public synchronized void myMethod() {
        // do stuff
}

public void myMethod() {
    synchronized(this) {
        // do stuff
    }
}
Stewart
  • 17,616
  • 8
  • 52
  • 80