title: Threads access on Synchronized Block/Code Java
body: <p>I was reading <a href="http://javarevisited.blogspot.com/2011/04/synchronization-in-java-synchronized.html" rel="nofollow">Synchronized</a> working. Here is the example:</p>
  
  <pre><code>public class Singleton{
  
  private static volatile Singleton _instance;
  
  public static Singleton getInstance(){
     if(_instance == null){
              synchronized(Singleton.class){
                if(_instance == null)
                _instance = new Singleton();
              }
     }
     return _instance;
  }
  </code></pre>
  
  <p>Let Suppose two Thread <code>A</code> and <code>B</code> are accessing <code>getInstance();</code> method, 
  If thread <code>A</code> is in <code>synchronized</code> block then thread <code>B</code> will skip that block and execute next block/statement or will wait/blocked until Thread <code>A</code> leave the  <code>synchronized</code> block.</p>
  
  <p>2nd What is, why is <code>Singleton.class</code> in <code>synchronized</code> parameter and when it could be <code>null</code></p>
  
  <p>and the below <code>Statement</code> is true?</p>
  
  <blockquote>
    <p>Intrinsic locks are on the object:</p>
  
  <pre><code>class A
  {
     public synchronized void method1(){...}
     public synchronized void method2(){...}
  }
  </code></pre>
    
    <p>If thread A is in <code>method1</code> then <code>threadB</code> cannot enter <code>method2</code> or any other synchronized method .</p>
  </blockquote>