title: synchronized(this) vs synchronized(MyClass.class)
body: <blockquote>
  <p><strong>Possible Duplicate:</strong><br />
  <a href="https://stackoverflow.com/questions/2056243/java-synchronized-block-for-class">Java Synchronized Block for .class</a></p>
  </blockquote>
  
  <p>I was reading through an <a href="http://javarevisited.blogspot.in/2011/04/synchronization-in-java-synchronized.html" rel="nofollow noreferrer">article</a> on synchronization. I am confused on below points and need more clarification</p>
  <ol>
  <li><p>For synchronization block. How<br/></p>
  <pre><code>synchronized (this) {
      // code
  }
  </code></pre>
  <p>differs from</p>
  <pre><code>synchronized (MyClass.class) {
      // code
  }
  </code></pre>
  </li>
  <li><p>Synchronizing instance method means threads will have to get exclusive lock on the instance, while synchronizing static method means thread will have to acquire a lock on whole class(correct me if I am wrong). So if a class has three methods and one of them is static synchronized then if a thread acquires lock on that method then that means it will acquire lock on the whole class. So does that mean the other two will also get locked and no other method will be able to access those two methods as the whole class is having lock?</p>
  </li>
  </ol>