title: 3 quick questions on Java's synchronized block
body: <p>As i understand the code below, in the <code>synchronized</code> block, <code>this</code> is an instance of a counter.</p>
  
  <p><strong>Question 1:</strong> In the example below, does this mean that when Thread A reaches the <code>synchronized</code> block, Thread B is blocked from doing anything to the instance of a Counter?. In other words, does this mean that Threads may continue to execute as they see please, but upon either reaches the  <code>synchronized</code> block, the other one is stopped from doing anything to the class until the block exited?</p>
  
  <pre><code>public class Counter {
  
      public void increment() {
          // Some code
  
          synchronized (this) {  // &lt;---- "this" is an instance of Counter
               // Some more code
          }
      }
  }
  </code></pre>
  
  <p>Compare code above with </p>
  
  <pre><code>public class Counter {
  
      List&lt;String&gt; listOfStrings = new ArrayList&lt;String&gt;();
  
      public void increment() {
          // Some code
  
          synchronized (listOfStrings) {  
               // Some code that deals with 
               //    listOfStrings 
          }
      }
  }
  </code></pre>
  
  <p><strong>Question 2:</strong> In the example above, once Thread A reaches the <code>synchronized</code> block, Thread B may continue reading and writing anything in the class with the exception of <code>listOfStrings</code> ArrayList, which is a <code>mutex</code> in the <code>synchronized</code> block. Is this correct?</p>
  
  <p><strong>Question 3:</strong> Is it further correct to assume that if we need to make modifications to multiple objects, <code>this</code> is the <code>mutex</code> we should use?</p>
  
  <p>For example:</p>
  
  <pre><code>public class Counter {
  
      List&lt;String&gt; listOfStrings = new ArrayList&lt;String&gt;();
      List&lt;Integers&gt; listOfIntegers = new ArrayList&lt;Integers&gt;();
  
      public void increment() {
          // Some code
  
          synchronized (this) {  
               // Some code that deals with 
               //    listOfStrings and listOfIntegers
          }
      }
  }
  </code></pre>
  
  <p>Am i understanding things correctly? Please correct if i misstated anything.</p>