title: Java synchronized blocks
body: <p>If we have a method:</p>
  
  <pre><code>public void doSomething(){
      synchronized(this){
          //some code processing here
      }
      String temp = "init"; //instead of i++
      synchronized(this){
          //some other code processing here
      }
  }
  </code></pre>
  
  <p>Is this method equivalent to <code>public synchronized void doSomething()</code>?</p>
  
  <p>Is there any reason <strong>not</strong> to assume that the thread scheduler in some executions would <strong>not</strong> result in effectively the same flow as synchronizing the whole function? That is:</p>
  
  <ul>
  <li><em>Thread1</em> enters the first synchronized block.</li>
  <li><em>Thread2</em> blocks.</li>
  <li><em>Thread1</em> continues with <code>i++</code> and moves to the second synchronized block while <em>Thread2</em> remains blocked.</li>
  <li>As a result, <em>Thread2</em> enters the method after <em>Thread1</em> has exited both synchronized blocks.</li>
  </ul>
  
  <p><strong>All I need to know is:</strong></p>
  
  <ul>
  <li>Can I count on all execution contexts that both threads (<em>Thread1</em> and <em>Thread2</em>) can be in the method at the same time? For example, <em>Thread2</em> in the first sync block and <em>Thread1</em> in the second sync block to achieve concurrency.</li>
  <li>Will there be some execution flows where only one thread will be in the method (at a time) effectively serializing the whole flow, making it equivalent to <code>public synchronized void doSomething()</code>?</li>
  </ul>