<html><body><div style="color:#000; background-color:#fff; font-family:verdana, helvetica, sans-serif;font-size:12px"><div id="yui_3_16_0_1_1443431830330_6433" class=""><br></div><div id="yui_3_16_0_1_1443431830330_6433" class="">Hello All,<br></div><div id="yui_3_16_0_1_1443431830330_6433" class=""><br id="yui_3_16_0_1_1443431830330_6637" class=""></div><div id="yui_3_16_0_1_1443431830330_6433" class="">    I am trying to understand why "<b id="yui_3_16_0_1_1443431830330_6741">Synchronizing on methods rather than on code blocks is slightly faster</b>" (source here <a href="https://weblogs.java.net/blog/johnsmart/archive/2008/03/using_hudson_en.html" id="yui_3_16_0_1_1443431830330_6653">https://weblogs.java.net/blog/johnsmart/archive/2008/03/using_hudson_en.html</a> ). </div><div id="yui_3_16_0_1_1443431830330_6433" class=""><br></div><div id="yui_3_16_0_1_1443431830330_6433" class=""><i id="yui_3_16_0_1_1443431830330_6747">public synchronized void testSynchMethod() {</i></div><div id="yui_3_16_0_1_1443431830330_6433" class=""><i>   x++;</i></div><div id="yui_3_16_0_1_1443431830330_6433" class=""><i>}</i><br></div><div id="yui_3_16_0_1_1443431830330_6433" class="" dir="ltr"><br></div><div id="yui_3_16_0_1_1443431830330_6433" class="" dir="ltr">VS</div><div id="yui_3_16_0_1_1443431830330_6433" class="" dir="ltr"><br></div><div id="yui_3_16_0_1_1443431830330_6433" class="" dir="ltr"><i id="yui_3_16_0_1_1443431830330_6746">public void testSynchBlock() {</i></div><div id="yui_3_16_0_1_1443431830330_6433" class="" dir="ltr"><i id="yui_3_16_0_1_1443431830330_6748">    synchronized (this) {</i></div><div id="yui_3_16_0_1_1443431830330_6433" class="" dir="ltr"><i id="yui_3_16_0_1_1443431830330_6753">        x++;</i></div><div id="yui_3_16_0_1_1443431830330_6433" class="" dir="ltr"><i id="yui_3_16_0_1_1443431830330_6754">    }</i></div><div id="yui_3_16_0_1_1443431830330_6433" class="" dir="ltr"><i id="yui_3_16_0_1_1443431830330_6752">}</i><br></div><div id="yui_3_16_0_1_1443431830330_6433" class=""><span class="" style="white-space:pre-wrap;"><br></span></div><div id="yui_3_16_0_1_1443431830330_6433" class=""><span class="" style="white-space:pre-wrap;" id="yui_3_16_0_1_1443431830330_6640">     </span>For this I did a trivial  JMH test and proved it. </div><div id="yui_3_16_0_1_1443431830330_6433" class=""><span class="" style="white-space: pre-wrap;"><br></span></div><div id="yui_3_16_0_1_1443431830330_6433" class=""><span class="" id="yui_3_16_0_1_1443431830330_6643" style="white-space: pre-wrap;">       </span>Could somebody please explain to me why is this happening? May be the explanation stays in the assembly code generated ...</div><div id="yui_3_16_0_1_1443431830330_6433" class=""><span class="" style="white-space:pre-wrap;" id="yui_3_16_0_1_1443431830330_6646">  </span></div><div id="yui_3_16_0_1_1443431830330_6433" class="" dir="ltr">Regards</div><div id="yui_3_16_0_1_1443431830330_6433" class="" dir="ltr">Ionut</div></div></body></html>