[concurrency-interest] Synchronizing on methods than on code blocks is faster

Ionut ionutb83 at yahoo.com
Mon Sep 28 05:26:59 EDT 2015

Hello All,

    I am trying to understand why "Synchronizing on methods rather than on code blocks is slightly faster" (source here https://weblogs.java.net/blog/johnsmart/archive/2008/03/using_hudson_en.html ). 
public synchronized void testSynchMethod() {   x++;}

public void testSynchBlock() {    synchronized (this) {        x++;    }}

 For this I did a trivial  JMH test and proved it. 
 Could somebody please explain to me why is this happening? May be the explanation stays in the assembly code generated ... RegardsIonut
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20150928/3755b70b/attachment.html>

More information about the Concurrency-interest mailing list