Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)
Can anyone help me understand the advantage of synchronized method over synchronized block?

1 Answer

0 votes
by (26.7k points)

Basically, there are no such advantages of using a synchronized method over a block. In the synchronized method, we do not need to include "this" as a reference.

For Method:

public synchronized void method() { // blocks "this" from here.... 

    ...

    ...

    ...

} // to here

For Block:

public void method() { 

    synchronized( this ) { // blocks "this" from here .... 

        ....

        ....

        ....

    }  // to here...

}

I hope this will help.

Want to become a Java Expert? Join Java Training now!!

Want to know more about Java? Watch this video on Java Tutorial for Beginners | Java Tutorial:

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...