This week's book giveaways are in the Refactoring and Agile forums. We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line! See this thread and this one for details.
What is the difference between a synchronized method and using a synchronized block. What difference does it make logically and which is more efficient
Naveen Kota<br />NMS Engineer
posted 10 years ago
A synchronzed method always locks on this object (unless it's a static method in which case the lock is held on a class-level).
A synchronized block locks on any object, however, locking the this object with a synchronized block is similar to using a synchronized method. But, it may be more efficient to use a synchonized block if the lock isn't nesseccary throughout the whole method.