title: having thread object lock vs class lock
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1536064/what-is-the-difference-between-synchronized-and-static-synchronized">What is the difference between synchronized and static synchronized?</a>  </p>
  </blockquote>
  
  
  
  <p>What is the advantage having object lock over class lock?</p>
  
  <p>For example, </p>
  
  <pre><code> public static void log2(String msg1, String msg2){
         synchronized(MyClass.class){
            log.writeln(msg1);
            log.writeln(msg2);  
         }
      }
  </code></pre>
  
  <p>and,</p>
  
  <pre><code>public void log2(String msg1, String msg2){
         synchronized(this){
            log.writeln(msg1);
            log.writeln(msg2);
         }
      }
  </code></pre>