Difference Between Synchronized Block and Method in Java

Category: Java   Tags: Java, Java Thread, Java MultiThread, Thread Synchronization, Java Producer Consumer

Difference between synchronized block and method in Java can be summarize as below:

1.
synchronized Method
Lock is acquired by thread when it enter method and released when it leaves method.

synchronized Block
Lock is acquired when they enter synchronized block and release when they leave synchronized block.
2.
synchronized Method
It force you to synchronize whole method even if some part of the method is not required to be be synchronize.

synchronized Block
It allows you to synchronize just the required part of code and therefore improves the performance.